Beispiel #1
0
static int
natm_usr_disconnect(struct socket *so)
{
    struct natmpcb *npcb;
    struct sockaddr_natm *snatm;
    struct atm_pseudoioctl api;
    struct atm_pseudohdr *aph;
    struct ifnet *ifp;
    int error = 0;
    int s2, s = SPLSOFTNET();
    int proto = so->so_proto->pr_protocol;

    npcb = (struct natmpcb *) so->so_pcb;
    if (npcb == NULL) {
	error = EINVAL;
	goto out;
    }

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

    /*
     * disable rx
     */

    ATM_PH_FLAGS(&api.aph) = ATM_PH_AAL5;
    ATM_PH_VPI(&api.aph) = npcb->npcb_vpi;
    ATM_PH_SETVCI(&api.aph, npcb->npcb_vci);
    api.rxhand = npcb;
    s2 = splimp();
    if (ifp->if_ioctl != NULL)
	ifp->if_ioctl(ifp, SIOCATMDIS, (caddr_t) &api);
    splx(s2);

    npcb_free(npcb, NPCB_REMOVE);
    soisdisconnected(so);

 out:
    splx(s);
    return (error);
}
Beispiel #2
0
static int
natm_usr_send(struct socket *so, int flags, struct mbuf *m, struct mbuf *nam,
	     struct mbuf *control)
{
    struct natmpcb *npcb;
    struct atm_pseudohdr *aph;
    int error = 0;
    int s = SPLSOFTNET();
    int proto = so->so_proto->pr_protocol;

    npcb = (struct natmpcb *) so->so_pcb;
    if (npcb == NULL) {
	error = EINVAL;
	goto out;
    }

    if (control && control->m_len) {
	m_freem(control);
	m_freem(m);
	error = EINVAL;
	goto out;
    }

    /*
     * send the data.   we must put an atm_pseudohdr on first
     */

    M_PREPEND(m, sizeof(*aph), M_WAITOK);
    if (m == NULL) {
        error = ENOBUFS;
	goto out;
    }
    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);

 out:
    splx(s);
    return (error);
}
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);
}
Beispiel #4
0
int natm_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
    struct mbuf *control, struct proc *p)
{
  int error = 0, s, s2;
  struct natmpcb *npcb;
  struct sockaddr_natm *snatm;
  struct atm_pseudoioctl api;
  struct atm_pseudohdr *aph;
  struct atm_rawioctl ario;
  struct ifnet *ifp;
  int proto = so->so_proto->pr_protocol;

  s = splsoftnet();

  npcb = (struct natmpcb *) so->so_pcb;

  if (npcb == NULL && req != PRU_ATTACH) {
    error = EINVAL;
    goto done;
  }
    

  switch (req) {
    case PRU_ATTACH:			/* attach protocol to up */

      if (npcb) {
	error = EISCONN;
	break;
      }

      if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
	if (proto == PROTO_NATMAAL5) 
          error = soreserve(so, natm5_sendspace, natm5_recvspace);
	else
          error = soreserve(so, natm0_sendspace, natm0_recvspace);
        if (error)
          break;
      }

      so->so_pcb = (caddr_t) (npcb = npcb_alloc(M_WAITOK));
      npcb->npcb_socket = so;

      break;

    case PRU_DETACH:			/* detach protocol from up */

      /*
       * we turn on 'drain' *before* we sofree.
       */

      npcb_free(npcb, NPCB_DESTROY);	/* drain */
      so->so_pcb = NULL;
      sofree(so);

      break;

    case PRU_CONNECT:			/* establish connection to peer */

      /*
       * validate nam and npcb
       */

      if (nam->m_len != sizeof(*snatm)) {
        error = EINVAL;
	break;
      }
      snatm = mtod(nam, struct sockaddr_natm *);
      if (snatm->snatm_len != sizeof(*snatm) ||
		(npcb->npcb_flags & NPCB_FREE) == 0) {
	error = EINVAL;
	break;
      }
      if (snatm->snatm_family != AF_NATM) {
	error = EAFNOSUPPORT;
	break;
      }

      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_flags & IFF_RUNNING) == 0) {
	error = ENXIO;
	break;
      }
      if (ifp->if_output != atm_output) {
	error = EAFNOSUPPORT;
	break;
      }


      /*
       * register us with the NATM PCB layer
       */

      if (npcb_add(npcb, ifp, snatm->snatm_vci, snatm->snatm_vpi) != npcb) {
        error = EADDRINUSE;
        break;
      }

      /*
       * enable rx
       */

      ATM_PH_FLAGS(&api.aph) = (proto == PROTO_NATMAAL5) ? ATM_PH_AAL5 : 0;
      ATM_PH_VPI(&api.aph) = npcb->npcb_vpi;
      ATM_PH_SETVCI(&api.aph, npcb->npcb_vci);
      api.rxhand = npcb;
      s2 = splnet();
      if (ifp->if_ioctl == NULL || 
	  ifp->if_ioctl(ifp, SIOCATMENA, (caddr_t) &api) != 0) {
	splx(s2);
	npcb_free(npcb, NPCB_REMOVE);
        error = EIO;
	break;
      }
      splx(s2);

      soisconnected(so);

      break;

    case PRU_DISCONNECT:		/* disconnect from peer */

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

      /*
       * disable rx
       */

      ATM_PH_FLAGS(&api.aph) = ATM_PH_AAL5;
      ATM_PH_VPI(&api.aph) = npcb->npcb_vpi;
      ATM_PH_SETVCI(&api.aph, npcb->npcb_vci);
      api.rxhand = npcb;
      s2 = splnet();
      if (ifp->if_ioctl != NULL)
	  ifp->if_ioctl(ifp, SIOCATMDIS, (caddr_t) &api);
      splx(s2);

      npcb_free(npcb, NPCB_REMOVE);
      soisdisconnected(so);

      break;

    case PRU_SHUTDOWN:			/* won't send any more data */
      socantsendmore(so);
      break;

    case PRU_SEND:			/* send this data */
      if (control && control->m_len) {
	m_freem(control);
	m_freem(m);
	error = EINVAL;
	break;
      }

      /*
       * send the data.   we must put an atm_pseudohdr on first
       */

      M_PREPEND(m, sizeof(*aph), M_WAITOK);
      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);

      break;

    case PRU_SENSE:			/* return status into m */
      /* return zero? */
      break;

    case PRU_PEERADDR:			/* fetch peer's address */
      snatm = mtod(nam, struct sockaddr_natm *);
      bzero(snatm, sizeof(*snatm));
      nam->m_len = snatm->snatm_len = sizeof(*snatm);
      snatm->snatm_family = AF_NATM;
#if defined(__NetBSD__) || defined(__OpenBSD__)
      bcopy(npcb->npcb_ifp->if_xname, snatm->snatm_if, sizeof(snatm->snatm_if));
#elif defined(__FreeBSD__)
      sprintf(snatm->snatm_if, "%s%d", npcb->npcb_ifp->if_name,
	npcb->npcb_ifp->if_unit);
#endif
      snatm->snatm_vci = npcb->npcb_vci;
      snatm->snatm_vpi = npcb->npcb_vpi;
      break;

    case PRU_CONTROL:			/* control operations on protocol */
      /*
       * raw atm ioctl.   comes in as a SIOCRAWATM.   we convert it to
       * SIOCXRAWATM and pass it to the driver.
       */
      if ((u_long)m == SIOCRAWATM) {
        if (npcb->npcb_ifp == NULL) {
          error = ENOTCONN;
          break;
        }
        ario.npcb = npcb;
        ario.rawvalue = *((int *)nam);
        error = npcb->npcb_ifp->if_ioctl(npcb->npcb_ifp, 
				SIOCXRAWATM, (caddr_t) &ario);
	if (!error) {
          if (ario.rawvalue) 
	    npcb->npcb_flags |= NPCB_RAW;
	  else
	    npcb->npcb_flags &= ~(NPCB_RAW);
	}

        break;
      }

      error = EOPNOTSUPP;
      break;

    case PRU_BIND:			/* bind socket to address */
    case PRU_LISTEN:			/* listen for connection */
    case PRU_ACCEPT:			/* accept connection from peer */
    case PRU_CONNECT2:			/* connect two sockets */
    case PRU_ABORT:			/* abort (fast DISCONNECT, DETACH) */
					/* (only happens if LISTEN socket) */
    case PRU_RCVD:			/* have taken data; more room now */
    case PRU_FASTTIMO:			/* 200ms timeout */
    case PRU_SLOWTIMO:			/* 500ms timeout */
    case PRU_RCVOOB:			/* retrieve out of band data */
    case PRU_SENDOOB:			/* send out of band data */
    case PRU_PROTORCV:			/* receive from below */
    case PRU_PROTOSEND:			/* send to below */
    case PRU_SOCKADDR:			/* fetch socket's address */
#ifdef DIAGNOSTIC
      printf("natm: PRU #%d unsupported\n", req);
#endif
      error = EOPNOTSUPP;
      break;
   
    default: panic("natm usrreq");
  }

done:
  splx(s);
  return(error);
}
Beispiel #5
0
void
hatm_rx(struct hatm_softc *sc, u_int cid, u_int flags, struct mbuf *m0,
    u_int len)
{
	struct hevcc *vcc;
	struct atm_pseudohdr aph;
	struct mbuf *m, *m1;
	u_int vpi, vci;
	u_char *ptr;

	DBG(sc, RX, ("cid=%#x flags=%#x len=%u mbuf=%p", cid, flags, len, m0));

	vcc = sc->vccs[cid];
	if (vcc == NULL)
		goto drop;

	if (flags & HE_REGM_RBRQ_CON_CLOSED) {
		if (vcc->vflags & HE_VCC_RX_CLOSING) {
			vcc->vflags &= ~HE_VCC_RX_CLOSING;
			if (vcc->param.flags & ATMIO_FLAG_ASYNC) {
				if (!(vcc->vflags & HE_VCC_OPEN))
					hatm_vcc_closed(sc, cid);
			} else
				cv_signal(&sc->vcc_cv);
		}
		goto drop;
	}

	if (!(vcc->vflags & HE_VCC_RX_OPEN))
		goto drop;

	if (flags & HE_REGM_RBRQ_HBUF_ERROR) {
		sc->istats.hbuf_error++;
		if (vcc->chain != NULL) {
			m_freem(vcc->chain);
			vcc->chain = vcc->last = NULL;
		}
		goto drop;
	}
	if (m0 == NULL) {
		sc->istats.no_rcv_mbuf++;
		return;
	}

	if ((m0->m_len = len) == 0) {
		sc->istats.empty_hbuf++;
		m_free(m0);

	} else if (vcc->chain == NULL) {
		sc->istats.rx_seg++;
		vcc->chain = vcc->last = m0;
		vcc->last->m_next = NULL;
		vcc->chain->m_pkthdr.len = m0->m_len;
		vcc->chain->m_pkthdr.rcvif = sc->ifp;

	} else {
		sc->istats.rx_seg++;
		vcc->last->m_next = m0;
		vcc->last = m0;
		vcc->last->m_next = NULL;
		vcc->chain->m_pkthdr.len += m0->m_len;
	}

	if (!(flags & HE_REGM_RBRQ_END_PDU))
		return;

	if (flags & HE_REGM_RBRQ_CRC_ERROR) {
		if (vcc->chain)
			m_freem(vcc->chain);
		vcc->chain = vcc->last = NULL;
		sc->istats.crc_error++;
		sc->ifp->if_ierrors++;
		return;
	}
	if (flags & HE_REGM_RBRQ_LEN_ERROR) {
		if (vcc->chain)
			m_freem(vcc->chain);
		vcc->chain = vcc->last = NULL;
		sc->istats.len_error++;
		sc->ifp->if_ierrors++;
		return;
	}

#ifdef HATM_DEBUG
	if (sc->debug & DBG_DUMP) {
		struct mbuf *tmp;

		for (tmp = vcc->chain; tmp != NULL; tmp = tmp->m_next) {
			printf("mbuf %p: len=%u\n", tmp, tmp->m_len);
			for (ptr = mtod(tmp, u_char *);
			    ptr < mtod(tmp, u_char *) + tmp->m_len; ptr++)
				printf("%02x ", *ptr);
			printf("\n");
		}
	}
#endif

	if (vcc->param.aal == ATMIO_AAL_5) {
		/*
		 * Need to remove padding and the trailer. The trailer
		 * may be split accross buffers according to 2.10.1.2
		 * Assume that mbufs sizes are even (buffer sizes and cell
		 * payload sizes are) and that there are no empty mbufs.
		 */
		m = vcc->last;
		if (m->m_len == 2) {
			/* Ah, oh, only part of CRC */
			if (m == vcc->chain) {
				/* ups */
				sc->istats.short_aal5++;
				m_freem(vcc->chain);
				vcc->chain = vcc->last = NULL;
				return;
			}
			for (m1 = vcc->chain; m1->m_next != m; m1 = m1->m_next)
				;
			ptr = (u_char *)m1->m_data + m1->m_len - 4;

		} else if (m->m_len == 4) {
			/* Ah, oh, only CRC */
			if (m == vcc->chain) {
				/* ups */
				sc->istats.short_aal5++;
				m_freem(vcc->chain);
				vcc->chain = vcc->last = NULL;
				return;
			}
			for (m1 = vcc->chain; m1->m_next != m; m1 = m1->m_next)
				;
			ptr = (u_char *)m1->m_data + m1->m_len - 2;

		} else if (m->m_len >= 6) {
			ptr = (u_char *)m->m_data + m->m_len - 6;
		} else
			panic("hatm_rx: bad mbuf len %d", m->m_len);

		len = (ptr[0] << 8) + ptr[1];
		if (len > (u_int)vcc->chain->m_pkthdr.len - 4) {
			sc->istats.badlen_aal5++;
			m_freem(vcc->chain);
			vcc->chain = vcc->last = NULL;
			return;
		}
		m_adj(vcc->chain, -(vcc->chain->m_pkthdr.len - len));
	}
	m = vcc->chain;
	vcc->chain = vcc->last = NULL;

#ifdef ENABLE_BPF
	if (!(vcc->param.flags & ATMIO_FLAG_NG) &&
	    (vcc->param.aal == ATMIO_AAL_5) &&
	    (vcc->param.flags & ATM_PH_LLCSNAP))
		BPF_MTAP(sc->ifp, m);
#endif

	vpi = HE_VPI(cid);
	vci = HE_VCI(cid);

	ATM_PH_FLAGS(&aph) = vcc->param.flags & 0xff;
	ATM_PH_VPI(&aph) = vpi;
	ATM_PH_SETVCI(&aph, vci);

	sc->ifp->if_ipackets++;
	/* this is in if_atmsubr.c */
	/* sc->ifp->if_ibytes += len; */

	vcc->ibytes += len;
	vcc->ipackets++;

#if 0
	{
		struct mbuf *tmp;

		for (tmp = m; tmp != NULL; tmp = tmp->m_next) {
			printf("mbuf %p: len=%u\n", tmp, tmp->m_len);
			for (ptr = mtod(tmp, u_char *);
			    ptr < mtod(tmp, u_char *) + tmp->m_len; ptr++)
				printf("%02x ", *ptr);
			printf("\n");
		}
	}
#endif

	atm_input(sc->ifp, &aph, m, vcc->rxhand);

	return;

  drop:
	if (m0 != NULL)
		m_free(m0);
}
Beispiel #6
0
int
main(int argc, char **argv)
{
	struct pvctxreq pvcreq;
	int s, ch;
	long bandwidth;
	char *if_name, *cp;
	int vpi = 0;
	int vci = 0;
	int joint_vpi = 0;
	int joint_vci = 0;
	int pcr = 0;
	int llcsnap = ATM_PH_LLCSNAP;
	int getinfo = 1;
	int subinterface = 0;
	int verbose = 1;

	if (argc < 2)
		usage();

	if_name = argv[1];
	if (argc > 2 && isdigit((unsigned char)argv[2][0]))
		str2vc(argv[2], &vpi, &vci);

	optind = 3;
	while ((ch = getopt(argc, argv, "p:b:j:snv")) != -1) {
		switch (ch) {
		case 'p':
			pcr = strtol(optarg, NULL, 0);
			getinfo = 0;
			break;
		case 'b':
			cp = NULL;
			bandwidth = strtol(optarg, &cp, 0);
			if (cp != NULL) {
				if (*cp == 'K' || *cp == 'k')
					bandwidth *= 1000;
				if (*cp == 'M' || *cp == 'm')
					bandwidth *= 1000000;
			}
			pcr = bandwidth / 8 / 48;
			getinfo = 0;
			break;
		case 'j':
			str2vc(optarg, &joint_vpi, &joint_vci);
			break;
		case 'n':
			llcsnap = 0;
			break;
		case 'v':
			verbose = 1;
			break;
		default:
			usage();
		}
	}

	if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
		err(1, "can't open socket");

	pvcreq.pvc_ifname[IFNAMSIZ-1] = '\0';
	strncpy(pvcreq.pvc_ifname, if_name, IFNAMSIZ-1);

	if (strncmp(if_name, "pvc", 3) == 0)
		/* pvc subinterface */
		subinterface = 1;
	
	ATM_PH_FLAGS(&pvcreq.pvc_aph) = ATM_PH_AAL5 | llcsnap;
	ATM_PH_VPI(&pvcreq.pvc_aph) = vpi;
	ATM_PH_SETVCI(&pvcreq.pvc_aph, vci);

	ATM_PH_FLAGS(&pvcreq.pvc_joint) = 0;
	ATM_PH_VPI(&pvcreq.pvc_joint) = joint_vpi;
	ATM_PH_SETVCI(&pvcreq.pvc_joint, joint_vci);
	
	pvcreq.pvc_pcr = pcr;

	if (getinfo) {
		if (ioctl(s, SIOCGPVCTX, &pvcreq) < 0)
			err(1, "SIOCSPVCTX");
	}
	else {
		if (verbose) {
		    printf("setting pvc tx: interface:%s vc:%d:%d ph=0x%x\n",
			   if_name, vpi, vci, ATM_PH_FLAGS(&pvcreq.pvc_aph));
		    printf("  joint:%d:%d, setting pcr:%d\n",
			   joint_vpi, joint_vci, pcr);
	        }

		if (ioctl(s, SIOCSPVCTX, &pvcreq) < 0)
				err(1, "SIOCSPVCTX");
	}

	pcr = pvcreq.pvc_pcr;

	/*
	 * print info
	 */
	printf("  %s", if_name);
	if (subinterface)
		printf(" (bound to %s)", pvcreq.pvc_ifname);
	printf(": vci:[%d:%d] (",
	       ATM_PH_VPI(&pvcreq.pvc_aph), ATM_PH_VCI(&pvcreq.pvc_aph));
	if (ATM_PH_FLAGS(&pvcreq.pvc_aph) & ATM_PH_AAL5)
		printf("AAL5");
	if (ATM_PH_FLAGS(&pvcreq.pvc_aph) & ATM_PH_LLCSNAP)
		printf("/LLCSNAP");
	printf(") ");
	if (pcr < 0)
		printf("(invalid)\n");
	else if (pcr == 0)
		printf("pcr:%d(full speed)\n", pcr);
	else if (pcr < 1000)
		printf("pcr:%d(%dbps)\n", pcr, pcr * 48 * 8);
	else if (pcr < 1000000)
		printf("pcr:%d(%dKbps)\n", pcr, pcr * 48 * 8 / 1000);
	else
		printf("pcr:%d(%dMbps)\n", pcr, pcr * 48 * 8 / 1000000);

	close(s);

	if (getinfo && pcr < 0) {
		fprintf(stderr, "can't get pvc info for vci:%d\n", vci);
		fprintf(stderr, "to setup a vci, use -p or -b option\n");
	}

	return (0);
}
Beispiel #7
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);
}
Beispiel #8
0
/*
 * atm_output: ATM output routine
 *   inputs:
 *     "ifp" = ATM interface to output to
 *     "m0" = the packet to output
 *     "dst" = the sockaddr to send to (either IP addr, or raw VPI/VCI)
 *     "ro" = the route to use
 *   returns: error code   [0 == ok]
 *
 *   note: special semantic: if (dst == NULL) then we assume "m" already
 *		has an atm_pseudohdr on it and just send it directly.
 *		[for native mode ATM output]   if dst is null, then
 *		ro->ro_rt must also be NULL.
 */
int
atm_output(struct ifnet *ifp, struct mbuf *m0, struct sockaddr *dst,
    struct route *ro)
{
	u_int16_t etype = 0;			/* if using LLC/SNAP */
	int error = 0, sz;
	struct atm_pseudohdr atmdst, *ad;
	struct mbuf *m = m0;
	struct atmllc *atmllc;
	struct atmllc *llc_hdr = NULL;
	u_int32_t atm_flags;

#ifdef MAC
	error = mac_ifnet_check_transmit(ifp, m);
	if (error)
		senderr(error);
#endif

	if (!((ifp->if_flags & IFF_UP) &&
	    (ifp->if_drv_flags & IFF_DRV_RUNNING)))
		senderr(ENETDOWN);

	/*
	 * check for non-native ATM traffic   (dst != NULL)
	 */
	if (dst) {
		switch (dst->sa_family) {

#if defined(INET) || defined(INET6)
		case AF_INET:
		case AF_INET6:
		{
			if (dst->sa_family == AF_INET6)
			        etype = ETHERTYPE_IPV6;
			else
			        etype = ETHERTYPE_IP;
			if (!atmresolve(ro->ro_rt, m, dst, &atmdst)) {
				m = NULL; 
				/* XXX: atmresolve already free'd it */
				senderr(EHOSTUNREACH);
				/* XXX: put ATMARP stuff here */
				/* XXX: watch who frees m on failure */
			}
		}
			break;
#endif /* INET || INET6 */

		case AF_UNSPEC:
			/*
			 * XXX: bpfwrite. assuming dst contains 12 bytes
			 * (atm pseudo header (4) + LLC/SNAP (8))
			 */
			bcopy(dst->sa_data, &atmdst, sizeof(atmdst));
			llc_hdr = (struct atmllc *)(dst->sa_data +
			    sizeof(atmdst));
			break;
			
		default:
			printf("%s: can't handle af%d\n", ifp->if_xname, 
			    dst->sa_family);
			senderr(EAFNOSUPPORT);
		}

		/*
		 * must add atm_pseudohdr to data
		 */
		sz = sizeof(atmdst);
		atm_flags = ATM_PH_FLAGS(&atmdst);
		if (atm_flags & ATM_PH_LLCSNAP)
			sz += 8;	/* sizeof snap == 8 */
		M_PREPEND(m, sz, M_NOWAIT);
		if (m == 0)
			senderr(ENOBUFS);
		ad = mtod(m, struct atm_pseudohdr *);
		*ad = atmdst;
		if (atm_flags & ATM_PH_LLCSNAP) {
			atmllc = (struct atmllc *)(ad + 1);
			if (llc_hdr == NULL) {
			        bcopy(ATMLLC_HDR, atmllc->llchdr, 
				      sizeof(atmllc->llchdr));
				/* note: in host order */
				ATM_LLC_SETTYPE(atmllc, etype); 
			}
			else
			        bcopy(llc_hdr, atmllc, sizeof(struct atmllc));
		}
	}

	if (ng_atm_output_p != NULL) {
		if ((error = (*ng_atm_output_p)(ifp, &m)) != 0) {
			if (m != NULL)
				m_freem(m);
			return (error);
		}
		if (m == NULL)
			return (0);
	}

	/*
	 * Queue message on interface, and start output if interface
	 * not yet active.
	 */
	if (!IF_HANDOFF_ADJ(&ifp->if_snd, m, ifp,
	    -(int)sizeof(struct atm_pseudohdr)))
		return (ENOBUFS);
	return (error);

bad:
	if (m)
		m_freem(m);
	return (error);
}
Beispiel #9
0
static int
natm_usr_connect(struct socket *so, struct mbuf *nam)
{
    struct natmpcb *npcb;
    struct sockaddr_natm *snatm;
    struct atm_pseudoioctl api;
    struct atm_pseudohdr *aph;
    struct ifnet *ifp;
    int error = 0;
    int s2, s = SPLSOFTNET();
    int proto = so->so_proto->pr_protocol;

    npcb = (struct natmpcb *) so->so_pcb;
    if (npcb == NULL) {
	error = EINVAL;
	goto out;
    }

    /*
     * validate nam and npcb
     */

    if (nam->m_len != sizeof(*snatm)) {
        error = EINVAL;
	goto out;
    }
    snatm = mtod(nam, struct sockaddr_natm *);
    if (snatm->snatm_len != sizeof(*snatm) ||
	(npcb->npcb_flags & NPCB_FREE) == 0) {
	error = EINVAL;
	goto out;
    }
    if (snatm->snatm_family != AF_NATM) {
	error = EAFNOSUPPORT;
	goto out;
    }

    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_flags & IFF_RUNNING) == 0) {
	error = ENXIO;
	goto out;
    }
    if (ifp->if_output != atm_output) {
	error = EAFNOSUPPORT;
	goto out;
    }

    /*
     * register us with the NATM PCB layer
     */

    if (npcb_add(npcb, ifp, snatm->snatm_vci, snatm->snatm_vpi) != npcb) {
        error = EADDRINUSE;
        goto out;
    }

    /*
     * enable rx
     */

    ATM_PH_FLAGS(&api.aph) = (proto == PROTO_NATMAAL5) ? ATM_PH_AAL5 : 0;
    ATM_PH_VPI(&api.aph) = npcb->npcb_vpi;
    ATM_PH_SETVCI(&api.aph, npcb->npcb_vci);
    api.rxhand = npcb;
    s2 = splimp();
    if (ifp->if_ioctl == NULL || 
	ifp->if_ioctl(ifp, SIOCATMENA, (caddr_t) &api) != 0) {
	splx(s2);
	npcb_free(npcb, NPCB_REMOVE);
        error = EIO;
	goto out;
    }
    splx(s2);

    soisconnected(so);

 out:
    splx(s);
    return (error);
}