if_tun.c (109526) | if_tun.c (109623) |
---|---|
1/* $NetBSD: if_tun.c,v 1.14 1994/06/29 06:36:25 cgd Exp $ */ 2 3/* 4 * Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk> 5 * Nottingham University 1987. 6 * 7 * This source may be freely distributed, however I would be interested 8 * in any changes that are made. 9 * 10 * This driver takes packets off the IP i/f and hands them up to a 11 * user process to have its wicked way with. This driver has it's 12 * roots in a similar driver written by Phil Cockcroft (formerly) at 13 * UCL. This driver is based much more on read/write/poll mode of 14 * operation though. 15 * | 1/* $NetBSD: if_tun.c,v 1.14 1994/06/29 06:36:25 cgd Exp $ */ 2 3/* 4 * Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk> 5 * Nottingham University 1987. 6 * 7 * This source may be freely distributed, however I would be interested 8 * in any changes that are made. 9 * 10 * This driver takes packets off the IP i/f and hands them up to a 11 * user process to have its wicked way with. This driver has it's 12 * roots in a similar driver written by Phil Cockcroft (formerly) at 13 * UCL. This driver is based much more on read/write/poll mode of 14 * operation though. 15 * |
16 * $FreeBSD: head/sys/net/if_tun.c 109526 2003-01-19 11:03:07Z phk $ | 16 * $FreeBSD: head/sys/net/if_tun.c 109623 2003-01-21 08:56:16Z alfred $ |
17 */ 18 19#include "opt_inet.h" 20#include "opt_mac.h" 21 22#include <sys/param.h> 23#include <sys/proc.h> 24#include <sys/systm.h> --- 210 unchanged lines hidden (view full) --- 235{ 236 struct tun_softc *sc; 237 struct ifnet *ifp; 238 239 if (!(dev->si_flags & SI_NAMED)) 240 dev = make_dev(&tun_cdevsw, minor(dev), 241 UID_UUCP, GID_DIALER, 0600, "tun%d", dev2unit(dev)); 242 | 17 */ 18 19#include "opt_inet.h" 20#include "opt_mac.h" 21 22#include <sys/param.h> 23#include <sys/proc.h> 24#include <sys/systm.h> --- 210 unchanged lines hidden (view full) --- 235{ 236 struct tun_softc *sc; 237 struct ifnet *ifp; 238 239 if (!(dev->si_flags & SI_NAMED)) 240 dev = make_dev(&tun_cdevsw, minor(dev), 241 UID_UUCP, GID_DIALER, 0600, "tun%d", dev2unit(dev)); 242 |
243 MALLOC(sc, struct tun_softc *, sizeof(*sc), M_TUN, M_WAITOK | M_ZERO); | 243 MALLOC(sc, struct tun_softc *, sizeof(*sc), M_TUN, M_ZERO); |
244 sc->tun_flags = TUN_INITED; 245 sc->next = tunhead; 246 tunhead = sc; 247 248 ifp = &sc->tun_if; 249 ifp->if_unit = dev2unit(dev); 250 ifp->if_name = TUNNAME; 251 ifp->if_mtu = TUNMTU; --- 237 unchanged lines hidden (view full) --- 489 m.m_data = (char *)⁡ 490 491 BPF_MTAP(ifp, &m); 492 } 493 494 /* prepend sockaddr? this may abort if the mbuf allocation fails */ 495 if (tp->tun_flags & TUN_LMODE) { 496 /* allocate space for sockaddr */ | 244 sc->tun_flags = TUN_INITED; 245 sc->next = tunhead; 246 tunhead = sc; 247 248 ifp = &sc->tun_if; 249 ifp->if_unit = dev2unit(dev); 250 ifp->if_name = TUNNAME; 251 ifp->if_mtu = TUNMTU; --- 237 unchanged lines hidden (view full) --- 489 m.m_data = (char *)⁡ 490 491 BPF_MTAP(ifp, &m); 492 } 493 494 /* prepend sockaddr? this may abort if the mbuf allocation fails */ 495 if (tp->tun_flags & TUN_LMODE) { 496 /* allocate space for sockaddr */ |
497 M_PREPEND(m0, dst->sa_len, M_DONTWAIT); | 497 M_PREPEND(m0, dst->sa_len, M_NOWAIT); |
498 499 /* if allocation failed drop packet */ 500 if (m0 == NULL) { 501 ifp->if_iqdrops++; 502 ifp->if_oerrors++; 503 return (ENOBUFS); 504 } else { 505 bcopy(dst, m0->m_data, dst->sa_len); 506 } 507 } 508 509 if (tp->tun_flags & TUN_IFHEAD) { 510 /* Prepend the address family */ | 498 499 /* if allocation failed drop packet */ 500 if (m0 == NULL) { 501 ifp->if_iqdrops++; 502 ifp->if_oerrors++; 503 return (ENOBUFS); 504 } else { 505 bcopy(dst, m0->m_data, dst->sa_len); 506 } 507 } 508 509 if (tp->tun_flags & TUN_IFHEAD) { 510 /* Prepend the address family */ |
511 M_PREPEND(m0, 4, M_DONTWAIT); | 511 M_PREPEND(m0, 4, M_NOWAIT); |
512 513 /* if allocation failed drop packet */ 514 if (m0 == NULL) { 515 ifp->if_iqdrops++; 516 ifp->if_oerrors++; 517 return (ENOBUFS); 518 } else 519 *(u_int32_t *)m0->m_data = htonl(dst->sa_family); --- 203 unchanged lines hidden (view full) --- 723 if (uio->uio_resid < 0 || uio->uio_resid > TUNMRU) { 724 TUNDEBUG("%s%d: len=%d!\n", ifp->if_name, ifp->if_unit, 725 uio->uio_resid); 726 return (EIO); 727 } 728 tlen = uio->uio_resid; 729 730 /* get a header mbuf */ | 512 513 /* if allocation failed drop packet */ 514 if (m0 == NULL) { 515 ifp->if_iqdrops++; 516 ifp->if_oerrors++; 517 return (ENOBUFS); 518 } else 519 *(u_int32_t *)m0->m_data = htonl(dst->sa_family); --- 203 unchanged lines hidden (view full) --- 723 if (uio->uio_resid < 0 || uio->uio_resid > TUNMRU) { 724 TUNDEBUG("%s%d: len=%d!\n", ifp->if_name, ifp->if_unit, 725 uio->uio_resid); 726 return (EIO); 727 } 728 tlen = uio->uio_resid; 729 730 /* get a header mbuf */ |
731 MGETHDR(m, M_DONTWAIT, MT_DATA); | 731 MGETHDR(m, M_NOWAIT, MT_DATA); |
732 if (m == NULL) 733 return (ENOBUFS); 734 mlen = MHLEN; 735 736 top = 0; 737 mp = ⊤ 738 while (error == 0 && uio->uio_resid > 0) { 739 m->m_len = min(mlen, uio->uio_resid); 740 error = uiomove(mtod (m, caddr_t), m->m_len, uio); 741 *mp = m; 742 mp = &m->m_next; 743 if (uio->uio_resid > 0) { | 732 if (m == NULL) 733 return (ENOBUFS); 734 mlen = MHLEN; 735 736 top = 0; 737 mp = ⊤ 738 while (error == 0 && uio->uio_resid > 0) { 739 m->m_len = min(mlen, uio->uio_resid); 740 error = uiomove(mtod (m, caddr_t), m->m_len, uio); 741 *mp = m; 742 mp = &m->m_next; 743 if (uio->uio_resid > 0) { |
744 MGET (m, M_DONTWAIT, MT_DATA); | 744 MGET (m, M_NOWAIT, MT_DATA); |
745 if (m == 0) { 746 error = ENOBUFS; 747 break; 748 } 749 mlen = MLEN; 750 } 751 } 752 if (error) { --- 93 unchanged lines hidden --- | 745 if (m == 0) { 746 error = ENOBUFS; 747 break; 748 } 749 mlen = MLEN; 750 } 751 } 752 if (error) { --- 93 unchanged lines hidden --- |