summaryrefslogtreecommitdiffstats
path: root/sys/net/if_tap.c
Commit message (Collapse)AuthorAgeFilesLines
* MFC r257078grehan2013-10-281-1/+1
| | | | | | | | | | | | | | Fix panic in the tap driver when a tap and vmnet interface were created after each other e.g. ifconfig tap0 ifconfig vmnet0 <panic> Appears to be a cut'n'paste error from the tap code to the vmnet code where the name string wasn't updated in the call to make_dev(). Approved by: re (glebius)
* Clear knlist before destroying it in tap(4) and tun(4). This fixes laterglebius2013-10-021-0/+1
| | | | | | crash, when a kqueue descriptor tries to dereference appropriate knotes. Approved by: re (kib)
* Don't clear the unused SI_CHEAPCLONE flag in tap_create()/tuncreate().davide2013-09-071-2/+0
| | | | Reviewed by: kib
* Mechanically substitute flags from historic mbuf allocator withglebius2012-12-051-1/+1
| | | | | | | | | malloc(9) flags within sys. Exceptions: - sys/contrib not touched - sys/mbuf.h edited manually
* Pass allocated unit number to make_dev, otherwise kernel panics later whiledavidxu2012-11-271-1/+1
| | | | | | cloning second tap. Reviewed by: kevlo,ed
* Make the "struct if_clone" opaque to users of the cloning API. Usersglebius2012-10-161-27/+33
| | | | | | | | | | | | now use function calls: if_clone_simple() if_clone_advanced() to initialize a cloner, instead of macros that initialize if_clone structure. Discussed with: brooks, bz, 1 year ago
* Correct misspelling in debug output.emaste2012-09-261-1/+1
|
* Avoid INVARIANTS panic destroying an in-use tap(4)emaste2012-09-251-5/+1
| | | | | | | | | | | | | | The requirement (implied by the KASSERT in tap_destroy) that the tap is closed isn't valid; destroy_dev will block in devdrn while other threads are in d_* functions. Note: if_tun had the same issue, addressed in SVN revisions r186391, r186483 and r186497. The use of the condvar there appears to be redundant with the functionality provided by destroy_dev. Sponsored by: ADARA Networks Reviewed by: dwhite MFC after: 2 weeks
* Implement SIOCGIFMEDIA for if_tap(4)emaste2012-07-061-4/+22
| | | | | | | | | Appease certain if_tap(4) consumers by providing simulated Ethernet media status. DragonFly commit 70d9a675bf5441cc854a843ead702d08928c37f3 Obtained from: DragonFly BSD
* Sort includes.trociny2012-06-071-1/+1
| | | | | Submitted by: Daan Vreeken <pa4dan Bliksem.VEHosting.nl> MFC after: 3 days
* Add VIMAGE support to if_tap.trociny2012-06-071-0/+11
| | | | | | PR: kern/152047, kern/158686 Submitted by: Daan Vreeken <pa4dan Bliksem.VEHosting.nl> MFC after: 1 week
* In r191367 the need for if_free_type() was removed and a new memberbrooks2011-11-111-1/+1
| | | | | | | | if_alloctype was used to store the origional interface type. Take advantage of this change by removing all existing uses of if_free_type() in favor of if_free(). MFC after: 1 Month
* Mark all SYSCTL_NODEs static that have no corresponding SYSCTL_DECLs.ed2011-11-071-1/+1
| | | | | | The SYSCTL_NODE macro defines a list that stores all child-elements of that node. If there's no SYSCTL_DECL macro anywhere else, there's no reason why it shouldn't be static.
* Get rid of D_PSEUDO.ed2011-10-181-1/+1
| | | | | | | | | | It seems the D_PSEUDO flag was meant to allow make_dev() to return NULL. Nowadays we have a different interface for that; make_dev_p(). There's no need to keep it there. While there, remove an unneeded D_NEEDMINOR from the gpio driver. Discussed with: gonzo@ (gpio)
* Fix a deficiency in the selinfo interface:attilio2011-08-251-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If a selinfo object is recorded (via selrecord()) and then it is quickly destroyed, with the waiters missing the opportunity to awake, at the next iteration they will find the selinfo object destroyed, causing a PF#. That happens because the selinfo interface has no way to drain the waiters before to destroy the registered selinfo object. Also this race is quite rare to get in practice, because it would require a selrecord(), a poll request by another thread and a quick destruction of the selrecord()'ed selinfo object. Fix this by adding the seldrain() routine which should be called before to destroy the selinfo objects (in order to avoid such case), and fix the present cases where it might have already been called. Sometimes, the context is safe enough to prevent this type of race, like it happens in device drivers which installs selinfo objects on poll callbacks. There, the destruction of the selinfo object happens at driver detach time, when all the filedescriptors should be already closed, thus there cannot be a race. For this case, mfi(4) device driver can be set as an example, as it implements a full correct logic for preventing this from happening. Sponsored by: Sandvine Incorporated Reported by: rstone Tested by: pluknet Reviewed by: jhb, kib Approved by: re (bz) MFC after: 3 weeks
* - Expand scope of tun/tap softc locks to cover more softc fields andjhb2010-09-221-91/+63
| | | | | | | | | | | | | | | | | driver-maintained ifnet fields (such as if_drv_flags). - Use soft locks as the mutex that protects each interface's knote list rather than using the global knote list lock. Also, use the softc for kn_hook instead of the cdev. - Use mtx_sleep() instead of tsleep() when blocking in the read routines. This fixes a lost wakeup race. - Remove D_NEEDGIANT now that the cdevsw routines use the softc lock where locking is needed. - Lock IFQ when calculating the result for FIONREAD in tap(4). tun(4) already did this. - Remove remaining spl calls. Submitted by: Marcin Cieslak saper of saper|info (3) MFC after: 2 weeks
* Verify interface up status using its link state onlyqingli2010-03-161-0/+2
| | | | | | | | | | | | | | if the interface has such capability. The interface capability flag indicates whether such capability exists. This approach is much more backward compatible. Physical device driver changes will be part of another commit. Also updated the ifconfig utility to show the LINKSTATE capability if present. Reviewed by: rwatson, imp, juli MFC after: 3 days
* The if_tap interface is of IFT_ETHERNET type, but itqingli2010-03-111-0/+2
| | | | | | | | | | | | | | | | does not set or update the if_link_state variable. As such RT_LINK_IS_UP() fails for the if_tap interface. Also, the RT_LINK_IS_UP() needs to bypass all loopback interfaces because loopback interfaces are considered up logically as long as the system is running. This patch fixes the above issues by setting and updating the if_link_state variable when the tap interface is opened or closed respectively. Similary approach is already done in the if_tun device. MFC after: 3 days
* In both if_tun and if_tap:kib2010-02-281-10/+3
| | | | | | | | | | | | | | | | Do not do additional dev_ref() on the newly created interface in the if_clone create method [1]. This reference is not needed and never removed, causing struct cdevpriv leakage. Remove the setting of SI_CHEAPCLONE flag as well, since it is unused. For dev_clone handlers, create cdevs with the call make_dev_credf(MAKEDEV_REF) instead of calling make_dev() and then dev_ref(), to avoid a race. Call drain_dev_clone_events() at the module unload time after dev_clone handler is deinstalled. Submitted by: Mikolaj Golub <to.my.trociny gmail com> [1] MFC after: 1 week
* Change the type of uio_resid member of struct uio from int to ssize_t.kib2009-06-251-1/+1
| | | | | | | | Note that this does not actually enable full-range i/o requests for 64 architectures, and is done now to update KBI only. Tested by: pho Reviewed by: jhb, bde (as part of the review of the bigger patch)
* Adapt vfs kqfilter to the shared vnode lock used by zfs write vop. Usekib2009-06-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | vnode interlock to protect the knote fields [1]. The locking assumes that shared vnode lock is held, thus we get exclusive access to knote either by exclusive vnode lock protection, or by shared vnode lock + vnode interlock. Do not use kl_locked() method to assert either lock ownership or the fact that curthread does not own the lock. For shared locks, ownership is not recorded, e.g. VOP_ISLOCKED can return LK_SHARED for the shared lock not owned by curthread, causing false positives in kqueue subsystem assertions about knlist lock. Remove kl_locked method from knlist lock vector, and add two separate assertion methods kl_assert_locked and kl_assert_unlocked, that are supposed to use proper asserts. Change knlist_init accordingly. Add convenience function knlist_init_mtx to reduce number of arguments for typical knlist initialization. Submitted by: jhb [1] Noted by: jhb [2] Reviewed by: jhb Tested by: rnoland
* Remove the splimp()/splx() calls around the setting of the MTU. They arescf2009-03-171-2/+0
| | | | | | | | no-op's that I inadvertently added. Even if locking is needed in general for the ioctl's, setting a single long will not need it due to the operation being atomic. Reported by: rwatson
* Add the SIOCSIFMTU ioctl handling directly to tap(4) permitting it toscf2009-03-161-0/+7
| | | | | | | | | | | | | have its MTU set higher than 1500 (ETHERMTU). Its new limit is now 65535 as enforced by ifhwioctl() in if.c This allows a tap(4) device to be added to a bridge, which requires all interface members to have the same MTU, with an interface configured for jumbo frames. QEMU may now connect to a network via tap(4) without requiring the real interface to have its MTU set to 1500 or lower. Reviewed by: rpaulo, bms MFC after: 1 week
* 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.
OpenPOWER on IntegriCloud