summaryrefslogtreecommitdiffstats
path: root/sys/net
Commit message (Collapse)AuthorAgeFilesLines
* Introduce locking around use of ifindex_table, whose use was previouslyrwatson2008-06-262-16/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | unsynchronized. While races were extremely rare, we've now had a couple of reports of panics in environments involving large numbers of IPSEC tunnels being added very quickly on an active system. - Add accessor functions ifnet_byindex(), ifaddr_byindex(), ifdev_byindex() to replace existing accessor macros. These functions now acquire the ifnet lock before derefencing the table. - Add IFNET_WLOCK_ASSERT(). - Add static accessor functions ifnet_setbyindex(), ifdev_setbyindex(), which set values in the table either asserting of acquiring the ifnet lock. - Use accessor functions throughout if.c to modify and read ifindex_table. - Rework ifnet attach/detach to lock around ifindex_table modification. Note that these changes simply close races around use of ifindex_table, and make no attempt to solve the probem of disappearing ifnets. Further refinement of this work, including with respect to ifindex_table resizing, is still required. In a future change, the ifnet lock should be converted from a mutex to an rwlock in order to reduce contention. Reviewed and tested by: brooks
* change a variable name ot stop it from colliding with other names injulian2008-06-261-7/+7
| | | | | | some situations. (i.e. in vimage) MFC after: 1 week
* Add support for the optional key in the GRE header.thompsa2008-06-202-3/+51
| | | | | PR: kern/114714 Submitted by: Cristian KLEIN
* Duh, wrong directory, needed to be in netinetjfv2008-06-112-464/+0
|
* Add generic TCP LRO code, moved from the ixgbe driver into netjfv2008-06-112-0/+464
|
* Don't enforce unique device minor number policy anymore.ed2008-06-112-2/+2
| | | | | | | | | | | | | | | | | | | | | | | 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)
* When RADIX_MPATH is enabled, the route selection is not rotatingqingli2008-05-302-6/+6
| | | | | | | | through the multipath entries. The hash value was a signed integer and was always giving a -1 value. PR: 123991 Submitted by: Barrett Lyon
* The if_check() function performed three actions:brooks2008-05-171-28/+10
| | | | | | | | | | | - verified that the ifp->if_snd.ifq_mtx was initalized for all attached interfaces. This was pointless because it was initalized for all interfaces in if_attach() so I've removed it. - Checked that ifp->if_snd.ifq_maxlen is initalized and set it to ifqmaxlen if unset. This makes more sense in if_attach() so I moved it there. - The first call of if_slowtimo(). Delete if_check() and call if_slowtimo() directly from the SYSINIT().
* Spelling and capitalization fixes.scf2008-05-161-4/+4
| | | | MFC after: 3 days
* Add missing braces in #if 0ed code.antoine2008-05-101-1/+2
| | | | | Approved by: rwatson (mentor) MFC after: 1 month
* move a #define from a place it shouldn't have been to a place it shouldjulian2008-05-102-4/+3
| | | | | have been. Basically my testign didn't ocver one case that this broke. thanks tinderbox!
* undef MAXFIBS before redefining itjulian2008-05-101-0/+1
|
* Add code to allow the system to handle multiple routing tables.julian2008-05-0915-149/+465
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This particular implementation is designed to be fully backwards compatible and to be MFC-able to 7.x (and 6.x) Currently the only protocol that can make use of the multiple tables is IPv4 Similar functionality exists in OpenBSD and Linux. From my notes: ----- One thing where FreeBSD has been falling behind, and which by chance I have some time to work on is "policy based routing", which allows different packet streams to be routed by more than just the destination address. Constraints: ------------ I want to make some form of this available in the 6.x tree (and by extension 7.x) , but FreeBSD in general needs it so I might as well do it in -current and back port the portions I need. One of the ways that this can be done is to have the ability to instantiate multiple kernel routing tables (which I will now refer to as "Forwarding Information Bases" or "FIBs" for political correctness reasons). Which FIB a particular packet uses to make the next hop decision can be decided by a number of mechanisms. The policies these mechanisms implement are the "Policies" referred to in "Policy based routing". One of the constraints I have if I try to back port this work to 6.x is that it must be implemented as a EXTENSION to the existing ABIs in 6.x so that third party applications do not need to be recompiled in timespan of the branch. This first version will not have some of the bells and whistles that will come with later versions. It will, for example, be limited to 16 tables in the first commit. Implementation method, Compatible version. (part 1) ------------------------------- For this reason I have implemented a "sufficient subset" of a multiple routing table solution in Perforce, and back-ported it to 6.x. (also in Perforce though not always caught up with what I have done in -current/P4). The subset allows a number of FIBs to be defined at compile time (8 is sufficient for my purposes in 6.x) and implements the changes needed to allow IPV4 to use them. I have not done the changes for ipv6 simply because I do not need it, and I do not have enough knowledge of ipv6 (e.g. neighbor discovery) needed to do it. Other protocol families are left untouched and should there be users with proprietary protocol families, they should continue to work and be oblivious to the existence of the extra FIBs. To understand how this is done, one must know that the current FIB code starts everything off with a single dimensional array of pointers to FIB head structures (One per protocol family), each of which in turn points to the trie of routes available to that family. The basic change in the ABI compatible version of the change is to extent that array to be a 2 dimensional array, so that instead of protocol family X looking at rt_tables[X] for the table it needs, it looks at rt_tables[Y][X] when for all protocol families except ipv4 Y is always 0. Code that is unaware of the change always just sees the first row of the table, which of course looks just like the one dimensional array that existed before. The entry points rtrequest(), rtalloc(), rtalloc1(), rtalloc_ign() are all maintained, but refer only to the first row of the array, so that existing callers in proprietary protocols can continue to do the "right thing". Some new entry points are added, for the exclusive use of ipv4 code called in_rtrequest(), in_rtalloc(), in_rtalloc1() and in_rtalloc_ign(), which have an extra argument which refers the code to the correct row. In addition, there are some new entry points (currently called rtalloc_fib() and friends) that check the Address family being looked up and call either rtalloc() (and friends) if the protocol is not IPv4 forcing the action to row 0 or to the appropriate row if it IS IPv4 (and that info is available). These are for calling from code that is not specific to any particular protocol. The way these are implemented would change in the non ABI preserving code to be added later. One feature of the first version of the code is that for ipv4, the interface routes show up automatically on all the FIBs, so that no matter what FIB you select you always have the basic direct attached hosts available to you. (rtinit() does this automatically). You CAN delete an interface route from one FIB should you want to but by default it's there. ARP information is also available in each FIB. It's assumed that the same machine would have the same MAC address, regardless of which FIB you are using to get to it. This brings us as to how the correct FIB is selected for an outgoing IPV4 packet. Firstly, all packets have a FIB associated with them. if nothing has been done to change it, it will be FIB 0. The FIB is changed in the following ways. Packets fall into one of a number of classes. 1/ locally generated packets, coming from a socket/PCB. Such packets select a FIB from a number associated with the socket/PCB. This in turn is inherited from the process, but can be changed by a socket option. The process in turn inherits it on fork. I have written a utility call setfib that acts a bit like nice.. setfib -3 ping target.example.com # will use fib 3 for ping. It is an obvious extension to make it a property of a jail but I have not done so. It can be achieved by combining the setfib and jail commands. 2/ packets received on an interface for forwarding. By default these packets would use table 0, (or possibly a number settable in a sysctl(not yet)). but prior to routing the firewall can inspect them (see below). (possibly in the future you may be able to associate a FIB with packets received on an interface.. An ifconfig arg, but not yet.) 3/ packets inspected by a packet classifier, which can arbitrarily associate a fib with it on a packet by packet basis. A fib assigned to a packet by a packet classifier (such as ipfw) would over-ride a fib associated by a more default source. (such as cases 1 or 2). 4/ a tcp listen socket associated with a fib will generate accept sockets that are associated with that same fib. 5/ Packets generated in response to some other packet (e.g. reset or icmp packets). These should use the FIB associated with the packet being reponded to. 6/ Packets generated during encapsulation. gif, tun and other tunnel interfaces will encapsulate using the FIB that was in effect withthe proces that set up the tunnel. thus setfib 1 ifconfig gif0 [tunnel instructions] will set the fib for the tunnel to use to be fib 1. Routing messages would be associated with their process, and thus select one FIB or another. messages from the kernel would be associated with the fib they refer to and would only be received by a routing socket associated with that fib. (not yet implemented) In addition Netstat has been edited to be able to cope with the fact that the array is now 2 dimensional. (It looks in system memory using libkvm (!)). Old versions of netstat see only the first FIB. In addition two sysctls are added to give: a) the number of FIBs compiled in (active) b) the default FIB of the calling process. Early testing experience: ------------------------- Basically our (IronPort's) appliance does this functionality already using ipfw fwd but that method has some drawbacks. For example, It can't fully simulate a routing table because it can't influence the socket's choice of local address when a connect() is done. Testing during the generating of these changes has been remarkably smooth so far. Multiple tables have co-existed with no notable side effects, and packets have been routes accordingly. ipfw has grown 2 new keywords: setfib N ip from anay to any count ip from any to any fib N In pf there seems to be a requirement to be able to give symbolic names to the fibs but I do not have that capacity. I am not sure if it is required. SCTP has interestingly enough built in support for this, called VRFs in Cisco parlance. it will be interesting to see how that handles it when it suddenly actually does something. Where to next: -------------------- After committing the ABI compatible version and MFCing it, I'd like to proceed in a forward direction in -current. this will result in some roto-tilling in the routing code. Firstly: the current code's idea of having a separate tree per protocol family, all of the same format, and pointed to by the 1 dimensional array is a bit silly. Especially when one considers that there is code that makes assumptions about every protocol having the same internal structures there. Some protocols don't WANT that sort of structure. (for example the whole idea of a netmask is foreign to appletalk). This needs to be made opaque to the external code. My suggested first change is to add routing method pointers to the 'domain' structure, along with information pointing the data. instead of having an array of pointers to uniform structures, there would be an array pointing to the 'domain' structures for each protocol address domain (protocol family), and the methods this reached would be called. The methods would have an argument that gives FIB number, but the protocol would be free to ignore it. When the ABI can be changed it raises the possibilty of the addition of a fib entry into the "struct route". Currently, the structure contains the sockaddr of the desination, and the resulting fib entry. To make this work fully, one could add a fib number so that given an address and a fib, one can find the third element, the fib entry. Interaction with the ARP layer/ LL layer would need to be revisited as well. Qing Li has been working on this already. This work was sponsored by Ironport Systems/Cisco Reviewed by: several including rwatson, bz and mlair (parts each) Obtained from: Ironport systems/Cisco
* Trim trailing whitespace at ends of lines.rwatson2008-05-091-16/+16
|
* Set D_TRACKCLOSE to avoid a race in devfs that could lead to orphaned bpfjhb2008-05-091-0/+1
| | | | | | devices never getting fully closed. MFC after: 3 days
* Add an option (compiled out by default)julian2008-04-291-0/+2
| | | | | | | | | to profile outoing packets for a number of mbuf chain related parameters e.g. number of mbufs, wasted space. probably will do with further work later. Reviewed by: various
* Check packet directions more properly instead of just checking receivedjkim2008-04-281-5/+5
| | | | | | | | interface is null. PR: kern/123138 Submitted by: Dmitry (hanabana at mail dot ru) MFC after: 1 week
* In function rtalloc_mpath(), do not try to release the lock if the ro_rtqingli2008-04-241-1/+3
| | | | | | pointer is NULL. Reported by: (pluknet at gmail dot com)
* Move "1000baseT" from IFM_SUBTYPE_ETHERNET_DESCRIPTIONS toantoine2008-04-201-1/+1
| | | | | | | | | | IFM_SUBTYPE_ETHERNET_ALIASES: there is already "1000baseTX" in IFM_SUBTYPE_ETHERNET_DESCRIPTIONS. This doesn't change ifconfig behaviour. PR: 45793 (maybe) Approved by: rwatson (mentor) MFC after: 1 month
* Delay the global registration of the struct ifnet in if_alloc() until afterbrooks2008-04-191-1/+1
| | | | | | | | we're certain the allocation will entierly succeed. This fixes a leak in a fairly unlikely case. Reported by: vijay singh <vijjus at rocketmail dot com> MFC after: 1 week
* Revert the previous commit and use M_PROMISC flag instead.jkim2008-04-151-8/+17
| | | | It is safer because it will never be used for outgoing packets.
* 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
* Remove M_SKIP_FIREWALL abuse and add more appropriate check.jkim2008-04-151-20/+11
| | | | | | Pointyhat to: jkim Reported by: Eugene Grosbein (eugen at kuzbass dot ru) MFC after: 3 days
* Make this file compile on IPv6 kernels.qingli2008-04-131-0/+2
|
* Make this compile also on non-IPv6 kernels.phk2008-04-131-0/+2
|
* Fix the build in case RADIX_MPATH is not defined.bz2008-04-131-1/+3
|
* These files handle the radix tree for the ECMP routes.qingli2008-04-132-0/+396
| | | | | | | | The original code from KAME did not take care of address aliases or multiple ip addresses that have the same prefix. Reviewed by: rwatson, gnn, sam, kmacy, julian
* This patch provides the back end support for equal-cost multi-pathqingli2008-04-135-1/+167
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (ECMP) for both IPv4 and IPv6. Previously, multipath route insertion is disallowed. For example, route add -net 192.103.54.0/24 10.9.44.1 route add -net 192.103.54.0/24 10.9.44.2 The second route insertion will trigger an error message of "add net 192.103.54.0/24: gateway 10.2.5.2: route already in table" Multiple default routes can also be inserted. Here is the netstat output: default 10.2.5.1 UGS 0 3074 bge0 => default 10.2.5.2 UGS 0 0 bge0 When multipath routes exist, the "route delete" command requires a specific gateway to be specified or else an error message would be displayed. For example, route delete default would fail and trigger the following error message: "route: writing to routing socket: No such process" "delete net default: not in table" On the other hand, route delete default 10.2.5.2 would be successful: "delete net default: gateway 10.2.5.2" One does not have to specify a gateway if there is only a single route for a particular destination. I need to perform more testings on address aliases and multiple interfaces that have the same IP prefixes. This patch as it stands today is not yet ready for prime time. Therefore, the ECMP code fragments are fully guarded by the RADIX_MPATH macro. Include the "options RADIX_MPATH" in the kernel configuration to enable this feature. Reviewed by: robert, sam, gnn, julian, kmacy
* Maintain and observe a ZBUF_FLAG_IMMUTABLE flag on zero-copy BPFrwatson2008-04-073-14/+125
| | | | | | | | | | | | | | | | | | | | | | buffer kernel descriptors, which is used to allow the buffer currently in the BPF "store" position to be assigned to userspace when it fills, even if userspace hasn't acknowledged the buffer in the "hold" position yet. To implement this, notify the buffer model when a buffer becomes full, and check that the store buffer is writable, not just for it being full, before trying to append new packet data. Shared memory buffers will be assigned to userspace at most once per fill, be it in the store or in the hold position. This removes the restriction that at most one shared memory can by owned by userspace, reducing the chances that userspace will need to call select() after acknowledging one buffer in order to wait for the next buffer when under high load. This more fully realizes the goal of zero system calls in order to process a high-speed packet stream from BPF. Update bpf.4 to reflect that both buffers may be owned by userspace at once; caution against assuming this.
* Coerce if_loop.c in the general direction of style(9):rwatson2008-04-071-33/+18
| | | | | | | | - Use ANSI function declarations - Remove use of 'register' keyword - Prefer style(9) return parens, white space MFC after: 1 month
* Add IFF_NEEDSGIANT to IFF_CANTCHANGE, to prevent user-level codeiedowse2008-03-271-1/+2
| | | | | | | | | | from clearing the IFF_NEEDSGIANT flag on Giant-locked interfaces. In particular, wpa_supplicant was doing this on USB interfaces, causing panics when Giant-locked code was then called without Giant. Submitted by: Alexey Popov Reviewed by: rwatson MFC after: 3 days
* Add a comment explaining that we initialize the 'a' buffer forrwatson2008-03-261-0/+5
| | | | | | | | | zero-copy to the store buffer position on the BPF descriptor, and the 'b' buffer as the free buffer in order to fill them in the order documented in bpf(4). MFC after: 4 months Suggested by: csjp
* expose if_purgemaddrs, it will be used by the vap code unless someonesam2008-03-252-2/+2
| | | | | | redesigns the mcast support code in the next few weeks MFC after: 3 weeks
* IFM_IEEE80211_IBSSMASTER hasn't been used in many years; replace itsam2008-03-251-2/+2
| | | | | | with IFM_IEEE80211_WDS which will be used by the forthcoming vap code MFC after: 3 weeks
* Replaced the misleading uses of a historical artefact M_TRYWAIT with M_WAIT.ru2008-03-256-38/+11
| | | | | | | | | | Removed dead code that assumed that M_TRYWAIT can return NULL; it's not true since the advent of MBUMA. Reviewed by: arch There are ongoing disputes as to whether we want to switch to directly using UMA flags M_WAITOK/M_NOWAIT for mbuf(9) allocation.
* Check for a NULL free buffer pointer in BPF before invokingrwatson2008-03-251-1/+1
| | | | | | | | bpf_canfreebuf() in order to avoid potentially calling a non-inlinable but trivial function in zero-copy buffer mode for every packet received when we couldn't free the buffer anyway. MFC after: 4 months
* Fix build with option BPF_JITTER.jkim2008-03-242-1/+3
|
* Remove redundant inclusions of net/bpfdesc.h.jkim2008-03-242-2/+0
|
* Introduce support for zero-copy BPF buffering, which reduces thecsjp2008-03-247-122/+1227
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | overhead of packet capture by allowing a user process to directly "loan" buffer memory to the kernel rather than using read(2) to explicitly copy data from kernel address space. The user process will issue new BPF ioctls to set the shared memory buffer mode and provide pointers to buffers and their size. The kernel then wires and maps the pages into kernel address space using sf_buf(9), which on supporting architectures will use the direct map region. The current "buffered" access mode remains the default, and support for zero-copy buffers must, for the time being, be explicitly enabled using a sysctl for the kernel to accept requests to use it. The kernel and user process synchronize use of the buffers with atomic operations, avoiding the need for system calls under load; the user process may use select()/poll()/kqueue() to manage blocking while waiting for network data if the user process is able to consume data faster than the kernel generates it. Patchs to libpcap are available to allow libpcap applications to transparently take advantage of this support. Detailed information on the new API may be found in bpf(4), including specific atomic operations and memory barriers required to synchronize buffer use safely. These changes modify the base BPF implementation to (roughly) abstrac the current buffer model, allowing the new shared memory model to be added, and add new monitoring statistics for netstat to print. The implementation, with the exception of some monitoring hanges that break the netstat monitoring ABI for BPF, will be MFC'd. Zerocopy bpf buffers are still considered experimental are disabled by default. To experiment with this new facility, adjust the net.bpf.zerocopy_enable sysctl variable to 1. Changes to libpcap will be made available as a patch for the time being, and further refinements to the implementation are expected. Sponsored by: Seccuris Inc. In collaboration with: rwatson Tested by: pwood, gallatin MFC after: 4 months [1] [1] Certain portions will probably not be MFCed, specifically things that can break the monitoring ABI.
* back out last change as Sam believes that it breaks multicast - need to ↵kmacy2008-03-201-2/+1
| | | | revisit after following up with pyun
* Don't re-initialize the interface if it is already running.kmacy2008-03-201-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | This one line change makes the following code found in many ethernet device drivers (at least em, igb, ixgbe, and cxgb) gratuitous case SIOCSIFADDR: if (ifa->ifa_addr->sa_family == AF_INET) { /* * XXX * Since resetting hardware takes a very long time * and results in link renegotiation we only * initialize the hardware only when it is absolutely * required. */ ifp->if_flags |= IFF_UP; if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { EM_CORE_LOCK(adapter); em_init_locked(adapter); EM_CORE_UNLOCK(adapter); } arp_ifinit(ifp, ifa); } else error = ether_ioctl(ifp, command, data); break;
* Replace really convoluted code that simplifies to "a ^= 0x01;"julian2008-03-191-9/+2
|
* Remove extra semicolons.thompsa2008-03-171-2/+2
| | | | Pointed out by: antoine
* Switch the LACP state machine over to its own mutex to protect the internals,thompsa2008-03-163-130/+156
| | | | | | | this means that it no longer grabs the lagg rwlock. Use two port table arrays which list the active ports for Tx and switch between them with an atomic op. Now the lagg rwlock is only exclusively locked for management (ioctls) and queuing of lacp control frames isnt needed.
* In keeping with style(9)'s recommendations on macros, use a ';'rwatson2008-03-164-5/+5
| | | | | | | | | after each SYSINIT() macro invocation. This makes a number of lightweight C parsers much happier with the FreeBSD kernel source, including cflow's prcc and lxr. MFC after: 1 month Discussed with: imp, rink
* Improve convergence of bpf_filter.c toward style(9).rwatson2008-03-091-40/+29
| | | | | MFC after: 3 weeks Submitted by: csjp
* Move IFF_NEEDSGIANT warning from if_ethersubr.c to if.c so it is displayedrwatson2008-03-072-3/+5
| | | | | | | | | | for all network interfaces, not just ethernet-like ones. Upgrade it to a louder WARNING and be explicit that the flag is obsolete. Support for IFF_NEEDSGIANT will be removed in a few months (see arch@ for details) and will not appear in 8.0. Upgrade if_watchdog to a WARNING.
* Improve EtherIP interaction with the bridgethompsa2008-03-061-2/+30
| | | | | | | | - Set M_BCAST|M_MCAST for incoming frames - Send the frame to a local interface if the bridge returns the mbuf Submitted by: Eugene Grosbein Tested by: Boris Kochergin
* Use RTFREE_LOCKED() instead of rtfree() when releasing a reference on thejhb2008-02-131-1/+1
| | | | | | | | 'rt' route in rtredirect() as 'rt' is always locked. MFC after: 1 week PR: kern/117913 Submitted by: Stefan Lambrev stefan.lambrev of moneybookers.com
* Add comment that bpfread() has multi-threading issues.rwatson2008-02-021-1/+4
| | | | Fix minor white space nit.
OpenPOWER on IntegriCloud