summaryrefslogtreecommitdiffstats
path: root/sys/net/if_tap.c
Commit message (Collapse)AuthorAgeFilesLines
* Retire the MALLOC and FREE macros. They are an abomination unto style(9).des2008-10-231-1/+1
| | | | MFC after: 3 months
* Replace all calls to minor() with dev2unit().ed2008-09-271-17/+17
| | | | | | | | | | | | | | | After I removed all the unit2minor()/minor2unit() calls from the kernel yesterday, I realised calling minor() everywhere is quite confusing. Character devices now only have the ability to store a unit number, not a minor number. Remove the confusion by using dev2unit() everywhere. This commit could also be considered as a bug fix. A lot of drivers call minor(), while they should actually be calling dev2unit(). In -CURRENT this isn't a problem, but it turns out we never had any problem reports related to that issue in the past. I suspect not many people connect more than 256 pieces of the same hardware. Reviewed by: kib
* Remove unit2minor() use from kernel code.ed2008-09-261-2/+2
| | | | | | | | | | | | | | | When I changed kern_conf.c three months ago I made device unit numbers equal to (unneeded) device minor numbers. We used to require bitshifting, because there were eight bits in the middle that were reserved for a device major number. Not very long after I turned dev2unit(), minor(), unit2minor() and minor2unit() into macro's. The unit2minor() and minor2unit() macro's were no-ops. We'd better not remove these four macro's from the kernel, because there is a lot of (external) code that may still depend on them. For now it's harmless to remove all invocations of unit2minor() and minor2unit(). Reviewed by: kib
* Add new TAPGIFNAME tap(4) character device ioctl. This is aemax2008-09-081-0/+6
| | | | | | | | convenient shortcut to obtain network interface name using file descriptor for character device. Obtained from: NetBSD MFC after: 1 week
* Don't enforce unique device minor number policy anymore.ed2008-06-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | Except for the case where we use the cloner library (clone_create() and friends), there is no reason to enforce a unique device minor number policy. There are various drivers in the source tree that allocate unr pools and such to provide minor numbers, without using them themselves. Because we still need to support unique device minor numbers for the cloner library, introduce a new flag called D_NEEDMINOR. All cdevsw's that are used in combination with the cloner library should be marked with this flag to make the cloning work. This means drivers can now freely use si_drv0 to store their own flags and state, making it effectively the same as si_drv1 and si_drv2. We still keep the minor() and dev2unit() routines around to make drivers happy. The NTFS code also used the minor number in its hash table. We should not do this anymore. If the si_drv0 field would be changed, it would no longer end up in the same list. Approved by: philip (mentor)
* Fix possible buffer overrun on 64-bit arch when generating MACemax2008-04-151-1/+3
| | | | | | | | address for tap interface. Reported by: Marc Lorner < marc dot loerner at hob dot de > Reviewed by: bms MFC after: 3 days
* Add a sysctl net.link.tap.up_on_open which defaults to zero; when itbms2007-03-191-1/+6
| | | | | | | | is non-zero, tap(4) instances will be marked IFF_UP on attach. PR: 110383 Requested by: Frank Behrens MFC after: 2 weeks
* Fix devfs cloning for non-superusers when net.link.tap.user_open is non-zero.bms2007-02-051-5/+2
| | | | | | Note: 'ifconfig tapX create' still requires PRIV_NET_IFCREATE privilege. Reviewed by: rwatson
* Implement ifnet cloning for tun(4)/tap(4).bms2007-02-041-32/+126
| | | | | | | | | | | | | | | | | | Make devfs cloning a sysctl/tunable which defaults to on. If devfs cloning is enabled, only the super-user may create tun(4)/tap(4)/vmnet(4) instances. Devfs cloning is still enabled by default; it may be disabled from the loader or via sysctl with "net.link.tap.devfs_cloning" and "net.link.tun.devfs_cloning". Disabling its use affects potentially all tun(4)/tap(4) consumers including OpenSSH, OpenVPN and VMware. PR: 105228 (potentially also 90413, 105570) Submitted by: Landon Fuller Tested by: Andrej Tobola Approved by: core (rwatson) MFC after: 4 weeks
* Drop unicast Ethernet frames not destined for the configured addressbms2007-02-031-0/+18
| | | | | | | | | | | | | | | | | | | | | of a tap(4) instance, if IFF_PROMISC is not set. In tap(4), we should emulate the effect IFF_PROMISC would have on hardware, otherwise we risk introducing layer 2 loops if tap(4) is used with bridges. This means not even bpf(4) gets to see them. This patch has been tested in a variety of situations. Multicast and broadcast frames are correctly allowed through. I have observed this behaviour causing problems with multiple QEMU instances hosted on the same FreeBSD machine. The checks in in ether_demux() [if_ethersubr.c, rev 1.222, line 638] are insufficient to prevent this bug from occurring, as ifp->if_vlantrunk will always be NULL for the non-vlan case. MFC after: 3 weeks PR: 86429 Submitted by: Pieter de Boer (with changes)
* Use int instead of u_int for the 'extra' argument to thebms2007-02-021-1/+1
| | | | | | | | | clone_create() KPI. This fixes a signedness bug in unit number comparisons. Submitted by: imp, Landon Fuller PR: kern/105228 MFC after: 2 weeks
* Sweep kernel replacing suser(9) calls with priv(9) calls, assigningrwatson2006-11-061-3/+7
| | | | | | | | | | | | | specific privilege names to a broad range of privileges. These may require some future tweaking. Sponsored by: nCircle Network Security, Inc. Obtained from: TrustedBSD Project Discussed on: arch@ Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri, Alex Lyashkov <umka at sevcity dot net>, Skip Ford <skip dot ford at verizon dot net>, Antoine Brodin <antoine dot brodin at laposte dot net>
* Currently, we initialize "error" to zero when it's declared, thencsjp2006-11-041-2/+1
| | | | | | | | | | | | | | | we never initialize it to anything else. However, in the case that m_uiotombuf fails, we return error (effectively reporting success). This appears to be a relic of an older revision of this file, where "error" used to be doing something useful. (See revision 1.1, where error is used in a loop with uiomove() instead of using m_uiotomubf). So instead on unconditionally reporting success in the case there is a failure in m_uiotombuf, explicitly return ENOBUFS. While we are here, garbage collect the error variable since it's no longer required. MFC after: 2 weeks
* Rename m_getm() to m_getm2() and rewrite it to allocate up to page sizedandre2006-11-021-1/+2
| | | | | | | | | | | | | | mbuf clusters. Add a flags parameter to accept M_PKTHDR and M_EOR mbuf chain flags. Provide compatibility macro for m_getm() calling m_getm2() with M_PKTHDR set. Rewrite m_uiotombuf() to use m_getm2() for mbuf allocation and do the uiomove() in a tight loop over the mbuf chain. Add a flags parameter to accept mbuf flags to be passed to m_getm2(). Adjust all callers for the extra parameter. Sponsored by: TCP/IP Optimization Fundraise 2005 MFC after: 3 month
* Fix our ioctl(2) implementation when the argument is "int". Newru2006-09-271-1/+13
| | | | | | | | | | | | | ioctls passing integer arguments should use the _IOWINT() macro. This fixes a lot of ioctl's not working on sparc64, most notable being keyboard/syscons ioctls. Full ABI compatibility is provided, with the bonus of fixing the handling of old ioctls on sparc64. Reviewed by: bde (with contributions) Tested by: emax, marius MFC after: 1 week
* Drop a pointless cast of ifp->if_softc to (struct tap_softc *).brooks2006-07-151-1/+1
|
* Revert the (int *) -> (intptr_t *) conversion done as part of rev. 1.59marius2006-05-301-10/+10
| | | | | | | | | | | for IOCTLs where casting data to intptr_t * isn't the right thing to do as _IO() isn't used for them but _IOR(..., int)/_IOW(..., int) are (i.e. for all IOCTLs except VMIO_SIOCSIFFLAGS), fixing tap(4) on big-endian LP64 machines. PR: sparc64/98084 OK'ed by: emax MFC after: 1 week
* Do not call knlist_destroy() in tapclose(). Instead call it when device isemax2006-05-171-4/+3
| | | | | | | | | actually destroyed. Also move call to knlist_init() into tapcreate(). This should fix panic described in kern/95357. PR: kern/95357 No response from: freebsd-current@ MFC after: 3 days
* Add kqueue(2) support on if_tap(4) interfaces. While I'm here, replaceemax2006-03-161-60/+153
| | | | | | | | | K&R style function declarations with ANSI style. Also fix endian bugs accessing ioctl arguments that are passed by value. PR: kern/93897 Submitted by: Vilmos Nebehaj < vili at huwico dot hu > MFC after: 1 week
* - Store pointer to the link-level address right in "struct ifnet"ru2005-11-111-2/+2
| | | | | | | | | | rather than in ifindex_table[]; all (except one) accesses are through ifp anyway. IF_LLADDR() works faster, and all (except one) ifaddr_byindex() users were converted to use ifp->if_addr. - Stop storing a (pointer to) Ethernet address in "struct arpcom", and drop the IFP2ENADDR() macro; all users have been converted to use IF_LLADDR() instead.
* Propagate rename of IFF_OACTIVE and IFF_RUNNING to IFF_DRV_OACTIVE andrwatson2005-08-091-8/+8
| | | | | | | | | | | | | | IFF_DRV_RUNNING, as well as the move from ifnet.if_flags to ifnet.if_drv_flags. Device drivers are now responsible for synchronizing access to these flags, as they are in if_drv_flags. This helps prevent races between the network stack and device driver in maintaining the interface flags field. Many __FreeBSD__ and __FreeBSD_version checks maintained and continued; some less so. Reviewed by: pjd, bz MFC after: 7 days
* Merge the dev_clone and dev_clone_cred event handlers into a singlerwatson2005-08-081-2/+4
| | | | | | | | | | | | | event handler, dev_clone, which accepts a credential argument. Implementors of the event can ignore it if they're not interested, and most do. This avoids having multiple event handler types and fall-back/precedence logic in devfs. This changes the kernel API for /dev cloning, and may affect third party packages containg cloning kernel modules. Requested by: phk MFC after: 3 days
* Stop embedding struct ifnet at the top of driver softcs. Instead thebrooks2005-06-101-14/+19
| | | | | | | | | | | | | | | | | | | | struct ifnet or the layer 2 common structure it was embedded in have been replaced with a struct ifnet pointer to be filled by a call to the new function, if_alloc(). The layer 2 common structure is also allocated via if_alloc() based on the interface type. It is hung off the new struct ifnet member, if_l2com. This change removes the size of these structures from the kernel ABI and will allow us to better manage them as interfaces come and go. Other changes of note: - Struct arpcom is no longer referenced in normal interface code. Instead the Ethernet address is accessed via the IFP2ENADDR() macro. To enforce this ac_enaddr has been renamed to _ac_enaddr. - The second argument to ether_ifattach is now always the mac address from driver private storage rather than sometimes being ac_enaddr. Reviewed by: sobomax, sam
* Separate out address-detaching part of if_detach into if_purgeaddrs,peadar2005-05-251-16/+3
| | | | | | | | | so if_tap doesn't need to rely on locally-rolled code to do same. The observable symptom of if_tap's bzero'ing the address details was a crash in "ifconfig tap0" after an if_tap device was closed. Reported By: Matti Saarinen (mjsaarin at cc dot helsinki dot fi)
* Change m_uiotombuf so it will accept offset at which data should be copiedemax2005-05-041-1/+1
| | | | | | | | | | to the mbuf. Offset cannot exceed MHLEN bytes. This is currently used to fix Ethernet header alignment problem on alpha and sparc64. Also change all users of m_uiotombuf to pass proper offset. Reviewed by: jmg, sam Tested by: Sten Spans "sten AT blinkenlights DOT nl" MFC after: 1 week
* Provide a sysctl (net.link.tap.user_open) to allow unpriviligedmdodd2005-04-131-3/+12
| | | | | | | acces to tap(4) device nodes based on file system permission. Duplicate the 'debug.if_tap_debug' sysctl under the 'net.link.tap' hierarchy.
* Explicitly hold a reference to the cdev we have just cloned. Thisphk2005-03-311-1/+3
| | | | | closes the race where the cdev was reclaimed before it ever made it back to devfs lookup.
* /* -> /*- for license, minor formatting changesimp2005-01-071-1/+1
|
* Don't include filedesc.hphk2004-12-221-3/+3
| | | | | | | Include fcntl.h Include selinfo.h (don't rely on vnode.h to do so) Check O_NONBLOCK instead of IO_NDELAY Don't include vnode.h
* Utilize m_uiotombuf() in device write method, instead of home-grownglebius2004-10-311-32/+6
| | | | | | | | implementation. This also gives a performance improvement, because m_uiotombuf() utilizes clusters. Approved by: julian (mentor) MFC after: 1 month
* Destroy global tapmtx when the if_tap module is unloaded.rwatson2004-09-171-0/+2
| | | | RELENG_5 candidated.
* Set IFF_RUNNING flag on the interface as soon as the control device is opened.emax2004-08-111-3/+9
|
* Second half of the dev_t cleanup.phk2004-06-171-1/+1
| | | | | | | | | | | The big lines are: NODEV -> NULL NOUDEV -> NODEV udev_t -> dev_t udev2dev() -> findcdev() Various minor adjustments including handling of userland access to kernel space struct cdev etc.
* Do the dreaded s/dev_t/struct cdev */phk2004-06-161-10/+10
| | | | Bump __FreeBSD_version accordingly.
* add missing #include <sys/module.h>phk2004-05-301-0/+1
|
* Correct a bug introduced with the recent clone API chang: when the clonerwatson2004-03-181-0/+1
| | | | | event handler for if_tap fails, make sure to clean up clone state to prevent a clone memory leak.
* sAdd a comment indicating why there continues to be a race condition inrwatson2004-03-181-5/+14
| | | | | | | | | | | | | | | | | | the tap driver, even with Giant over the cdev operation vector, due to a non-atomic test-and-set of the si_drv1 field in the dev_t. This bug exists with Giant under high memory pressure, as malloc() may sleep in tapcreate(), but is less likely to occur. The resolution will probably be to cover si_drv1 using the global tapmtx since no softc is available, but I need to think about this problem more generally across a range of drivers using si_drv1 in combination with SI_CHEAPCLONE to defer expensive allocation to open(). Correct what appears to be a bug in the original if_tap implementation, in which tapopen() will panic if a tap device instance is opened more than once due to an incorrect assertion -- only triggered if INVARIANTS is compiled in (i.e., when built into a kernel). Return EBUSY instead. Expand mtx_lock() coverage using tp->tap_mtx to include tp->ether_addr.
* Add tap_mtx to tap_softc in order to protect per-softc variablesrwatson2004-03-171-2/+39
| | | | | | | (tap_pid, tap_flags). if_tap should now be entirely MPSAFE. Committed from: Bamboo house by ocean in Taiwan Tropical paradise provided by: Chia-liang Kao <clkao@clkao.org>
* Lock down global variables in if_tap (primarily, the tap softc list);rwatson2004-03-151-3/+28
| | | | | | | | | | | | | | | add tapmtx, which protects globale variables. Notes: - The EBUSY check in MOD_UNLOAD may be subject to a race. Moving the event handler unregister inside the mutex grab may prevent that race. - Locking of global variables safely is now possible because tapclones is only modified when the module is loading or unloading, thanks to phk's recent chang to clone_setup(). - softc locking to follow.
* Add clone_setup() function rather than rely on lazy initialization.phk2004-03-111-0/+1
| | | | Requested by: rwatson
* Fix handling of tap/vmnet flag in relation to cloning and properly enforcephk2004-03-101-10/+8
| | | | | | largest supported unit number for this device driver. Reported by: Kaho Toshikazu <kaho@easy.es.tuat.ac.jp>
* Don't set d_flags twice. The second setting clobbered D_NOGIANT.bde2004-02-241-2/+1
|
* Device megapatch 4/6:phk2004-02-211-0/+2
| | | | | | | | Introduce d_version field in struct cdevsw, this must always be initialized to D_VERSION. Flip sense of D_NOGIANT flag to D_NEEDGIANT, this involves removing four D_NOGIANT flags and adding 145 D_NEEDGIANT flags.
* Device megapatch 2/6:phk2004-02-211-129/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds a couple of functions for pseudodrivers to use for implementing cloning in a manner we will be able to lock down (shortly). Basically what happens is that pseudo drivers get a way to ask for "give me the dev_t with this unit number" or alternatively "give me a dev_t with the lowest guaranteed free unit number" (there is unfortunately a lot of non-POLA in the exact numeric value of this number, just live with it for now) Managing the unit number space this way removes the need to use rman(9) to do so in the drivers this greatly simplifies the code in the drivers because even using rman(9) they still needed to manage their dev_t's anyway. I have taken the if_tun, if_tap, snp and nmdm drivers through the mill, partly because they (ab)used makedev(), but mostly because together they represent three different problems for device-cloning: if_tun and snp is the plain case: just give me a device. if_tap has two kinds of devices, with a flag for device type. nmdm has paired devices (ala pty) can you can clone either of them.
* - Implement selwakeuppri() which allows raising the priority of atanimura2003-11-091-2/+2
| | | | | | | | | | | | | thread being waken up. The thread waken up can run at a priority as high as after tsleep(). - Replace selwakeup()s with selwakeuppri()s and pass appropriate priorities. - Add cv_broadcastpri() which raises the priority of the broadcast threads. Used by selwakeuppri() if collision occurs. Not objected in: -arch, -current
* Replace the if_name and if_unit members of struct ifnet with new membersbrooks2003-10-311-37/+34
| | | | | | | | | | | | | if_xname, if_dname, and if_dunit. if_xname is the name of the interface and if_dname/unit are the driver name and instance. This change paves the way for interface renaming and enhanced pseudo device creation and configuration symantics. Approved By: re (in principle) Reviewed By: njl, imp Tested On: i386, amd64, sparc64 Obtained From: NetBSD (if_xname)
* Gigacommit to improve device-driver source compatibility betweenphk2003-03-031-13/+8
| | | | | | | | | | | | | branches: Initialize struct cdevsw using C99 sparse initializtion and remove all initializations to default values. This patch is automatically generated and has been tested by compiling LINT with all the fields in struct cdevsw in reverse order on alpha, sparc64 and i386. Approved by: re(scottl)
* More low-hanging fruit: kill caddr_t in calls to wakeup(9) / [mt]sleep(9).des2003-03-021-2/+2
|
* Clean up whitespace, s/register //, refrain from strong urge to ANSIfy.des2003-03-021-47/+47
|
* uiomove-related caddr_t -> void * (just the low-hanging fruit)des2003-03-021-2/+2
|
OpenPOWER on IntegriCloud