Commit Graph

102 Commits

Author SHA1 Message Date
thorpej
2685996b0e Merge thorpej-cfargs branch:
Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
  actually needed.
- Don't be explicit about what interface attribute is attaching if
  the device only has one.  (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
  situations, making is visibly easier to see when indirect config is
  in play, and allowing for future change in semantics.  (As of now,
  this is just a wrapper around config_match(), but that is an
  implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance.  This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
2021-04-24 23:36:23 +00:00
msaitoh
57920690e6 s/occurence/occurrence/ 2020-09-29 02:58:51 +00:00
jdolecek
60ef6bcfd7 add a config fragment to include all ppbus devices to make it simpler
to compile test; right now assumes attachment of atppc(4) via acpi
2020-02-04 21:09:03 +00:00
jdolecek
31b98d959c finish adoption of <net/if_stats.h> 2020-02-04 20:46:51 +00:00
skrll
11704b9814 Adopt <net/if_stats.h> 2020-02-04 07:35:21 +00:00
msaitoh
ba5c90c4a4 s/sucess/success/ in comment. 2019-12-27 09:45:26 +00:00
msaitoh
c46d1cc12b s/manaul/manual/ in comment. 2019-12-27 09:28:41 +00:00
chs
d47bcd296c in many device attach paths, allocate memory with M_WAITOK instead of M_NOWAIT
and remove code to handle failures that can no longer happen.
2019-11-10 21:16:21 +00:00
maxv
ec3805d3b8 Remove the 'copy' argument from m_devget(), unused. While here rename
off0->off.
2018-11-15 10:56:29 +00:00
mlelstv
8e369ccc39 When refactoring interface drivers after netbsd-4, the SIOCINITIFADDR
ioctl was passed through ifioctl_common, because the case falls through
to the SIOCSIFFLAGS case. The common handler however doesn't implement
SIOCINITIFADDR, so an attempt to configure plip always failed with ENOTTY.
2018-11-05 18:37:18 +00:00
riastradh
d1579b2d70 Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int.  The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER!  Some subsystems have

	#define min(a, b)	((a) < (b) ? (a) : (b))
	#define max(a, b)	((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX.  Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate.  But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all.  (Who knows, maybe in some cases integer
truncation is actually intended!)
2018-09-03 16:29:22 +00:00
msaitoh
c33f30648e Initialize some members in a mbuf which is on stack. 2018-07-25 07:55:44 +00:00
msaitoh
3cd62456f9 Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

 This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
2018-06-26 06:47:57 +00:00
msaitoh
3d3638f672 KNF & fix typo. No functional change. 2018-06-25 13:28:12 +00:00
maxv
49bf63c13e spl leak, found by Mootja 2017-06-25 12:27:13 +00:00
christos
52e1f28ccd Catch up with other networking changes (John D. Baker) 2016-05-08 03:11:33 +00:00
knakahara
b76ec0b083 IFQ_ENQUEUE refactor (3/3) : eliminate pktattr argument from IFQ_ENQUEUE caller 2016-04-20 09:01:03 +00:00
dholland
0107a58a68 Add missing va_end, from David Binderman in PR 50797. 2016-02-14 18:11:16 +00:00
dholland
1fbab01a93 More on PR 41200: headers that declare ioctls should include sys/ioccom.h.
This covers (I think) all the MI headers outside of external/ (and dist/).
2015-09-06 06:00:59 +00:00
christos
2a70d96fc0 PR/49281: John D. Baker: fix debugging format
XXX: pullup 7
2014-10-14 01:04:39 +00:00
dholland
f9228f4225 Add d_discard to all struct cdevsw instances I could find.
All have been set to "nodiscard"; some should get a real implementation.
2014-07-25 08:10:31 +00:00
dholland
da7427b662 "peripheral", not "peripherial". 2014-07-13 17:12:23 +00:00
rmind
60d350cf6d - Implement pktqueue interface for lockless IP input queue.
- Replace ipintrq and ip6intrq with the pktqueue mechanism.
- Eliminate kernel-lock from ipintr() and ip6intr().
- Some preparation work to push softnet_lock out of ipintr().

Discussed on tech-net.
2014-06-05 23:48:16 +00:00
dholland
a68f9396b6 Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
2014-03-16 05:20:22 +00:00
chs
cbab9cadce split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
2012-10-27 17:17:22 +00:00
joerg
3eb244d801 Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
2011-07-17 20:54:30 +00:00
rmind
6a0660a9b0 Replace some ltsleep() uses with kpause() and tsleep(). 2011-05-13 22:35:50 +00:00
rmind
3bc401dcc3 Eliminate few references to ltsleep. 2011-05-13 22:28:40 +00:00
phx
e786622161 Include <sys/gpio.h> for GPIOMAXNAME to make it compile again when a gpio(4)
device is attached.
2011-02-18 21:38:17 +00:00
joerg
58e867556f Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
2010-04-05 07:19:28 +00:00
pooka
10fe49d72c Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client.  This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached.  However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff.  ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
2010-01-19 22:06:18 +00:00
he
c90853c4da Make this actually build, as part of the sgimips GENERIC32_IP2x kernel. 2009-11-11 15:34:37 +00:00
dyoung
8b43bcb6ad Don't deactivate a child before detaching it, that's not necessary.
Don't take a device off of the ppbus(4)'s list of children in the
detach routine, but add a child-detachment hook that does it for
us.  As a nice side-effect, we can probably detach ppbus(4) children
with drvctl(8), now.

Compile-tested, only.

XXX Does anybody even use ppbus(4)?  It's not even in the ALL
XXX configuration for i386!
2009-11-07 00:05:49 +00:00
cegger
56ce1b94f8 buildfix: include <sys/device.h> for device_t 2009-04-05 09:56:16 +00:00
christos
9a5d3f2817 replace bitmask_snprintf(9) with snprintb(3) 2008-12-16 22:35:21 +00:00
dyoung
de87fe677d *** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02🇩🇪ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address.  (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior.  Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability.  KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR.  In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr.  That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR.  In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR.  For example, pull ..._init() out of any switch
statement that looks like this:

        switch (...->sa_family) {
        case ...:
                ..._init();
                ...
                break;
        ...
        default:
                ..._init();
                ...
                break;
        }

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

        switch (x & (IFF_UP|IFF_RUNNING)) {
        case 0:
                ...
                break;
        case IFF_RUNNING:
                ...
                break;
        case IFF_UP:
                ...
                break;
        case IFF_UP|IFF_RUNNING:
                ...
                break;
        }

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure.  Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls.  In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source.  In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively.  Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset.  Delete unnecessary casts to void *.  Use
sockaddr_in_init() and sockaddr_in6_init().  Compare pointers with
NULL instead of "testing truth".  Replace some instances of (type
*)0 with NULL.  Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 00:20:01 +00:00
cegger
6a2e2c8cfd use device_lookup_private to get softc 2008-06-11 19:28:52 +00:00
cegger
b574865ea4 gpio(4): Extend with open/close to request/release the ppbus(4) on open/close.
ppbus(4): Extend to attach on gpiobus.
From Hans Rosenfeld from tech-kern:
http://mail-index.netbsd.org/tech-kern/2008/04/28/msg001168.html
Hint: Hans sent me this diff which differs in the one from tech-kern in:
- 2-clause license
- sprinkled some consts
2008-04-29 14:07:36 +00:00
martin
ce099b4099 Remove clause 3 and 4 from TNF licenses 2008-04-28 20:22:51 +00:00
ad
a2249ef75c Make ntp, pmc, reboot, sysarch, time syscalls MPSAFE. 2008-04-21 12:56:30 +00:00
cegger
5db505451b Fix panics at boot and some other misc bugs. From Hans Rosenfeld. 2008-04-18 14:56:40 +00:00
cegger
376411d2dd device_t / softc split. From Hans Rosenfeld. 2008-04-16 09:39:01 +00:00
cegger
7b52308352 Use %zu format specifier for size_t. Fixes build error on shark. 2008-04-15 22:50:33 +00:00
cegger
2ae1aec4f9 Make this build without options LPT_VERBOSE and LPT_DEBUG. From Hans Rosenfeld. 2008-04-15 19:06:16 +00:00
cegger
57f80cdb16 Make this build. From Hans Rosenfeld. 2008-04-15 19:03:26 +00:00
cegger
b849cd90e5 device_t / softc split. From Hans Rosenfeld 2008-04-15 15:02:28 +00:00
cegger
1b044f414a use aprint_*_dev and device_xname 2008-04-08 07:35:35 +00:00
tsutsui
40009ad586 struct lpt_softc doesn't have sc_dev in it. Use ppbus_dev.sc_dev. 2008-02-27 12:52:36 +00:00
dyoung
0ba85a6f89 Use device_t and accessors. Use &sc->sc_dev instead of cast to
device_t.  Remove superfluous detach warning.
2008-02-22 23:11:35 +00:00
dyoung
2ccede0a9c Start patching up the kernel so that a network driver always has
the opportunity to handle an ioctl before generic ifioctl handling
occurs.  This will ease extending the kernel and sharing of code
between drivers.

First steps:  Make the signature of ifioctl_common() match struct
ifinet->if_ioctl.  Convert SIOCSIFCAP and SIOCSIFMTU to the new
ifioctl() regime, throughout the kernel.
2008-02-07 01:21:52 +00:00