Commit Graph

233 Commits

Author SHA1 Message Date
christos 942a145f69 PR/40603: Christoph Badura: unprivileged users can add and delete interface
link addresses. Fixed by centralizing the test as suggested. Will pull up
to 5.0 once submitter tests the fix.
2009-02-12 19:05:36 +00:00
christos 461a86f9bd merge christos-time_t 2009-01-11 02:45:45 +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
dyoung 398adeb7b9 Do not gratuitously cast to void *. 2008-10-24 21:46:09 +00:00
dyoung 71367efb93 Undo a change in my last commit that was not suppsoed to be committed. 2008-10-24 17:14:29 +00:00
dyoung cf969cfa5a Constify the rt_addrinfo argument to the ifa_rtrequest member
function of struct ifaddr.
2008-10-24 17:07:33 +00:00
yamt fff57c5525 merge yamt-pf42 branch.
(import newer pf from OpenBSD 4.2)

ok'ed by peter@.  requested by core@
2008-06-18 09:06:25 +00:00
christos bc168f2766 - add if_alloc (ours just mallocs), and if_initname and use them (from FreeBSD)
- kill memsets where M_ZERO can be used.
2008-06-15 16:37:21 +00:00
dyoung e78c6441d1 Cosmetic; reduce excessive parenthesization. 2008-05-13 20:40:33 +00:00
dyoung 2f604e903b Let us call ioctl(SIOC[ADG]LIFADDR) with a link-layer address on
an AF_LINK socket, only, to be consistent with SIOC[ADG]LIFADDR
behavior on AF_INET and AF_INET6 sockets.  Let us create AF_LINK
sockets for this purpose.  Note that most operations on AF_LINK
sockets are not implemented.
2008-05-13 18:09:22 +00:00
dyoung 4dd5ca7947 Add kernel support for adding/removing link-layer addresses using
SIOCALIFADDR AND SIOCDLIFADDR, respectively.  Corresponding
ifconfig(8) changes are coming soon.
2008-05-11 23:48:07 +00:00
ad 971df547a1 kern/38502 ifconfig wi0 hangs
Don't acquire the socket lock for PRU_CONTROL.
2008-04-29 18:42:26 +00:00
martin ce099b4099 Remove clause 3 and 4 from TNF licenses 2008-04-28 20:22:51 +00:00
martin f9b83801e8 Make it compile if !COMPAT_OSOCK 2008-04-24 13:30:52 +00:00
ad 15e29e981b Merge the socket locking patch:
- Socket layer becomes MP safe.
- Unix protocols become MP safe.
- Allows protocol processing interrupts to safely block on locks.
- Fixes a number of race conditions.

With much feedback from matt@ and plunky@.
2008-04-24 11:38:36 +00:00
dyoung 8a7761f76c Cosmetic: shorten staircases. Join some lines. 2008-02-29 21:23:55 +00:00
martin 035ac59527 Make it compile w/o INET6 2008-02-07 08:48:16 +00:00
xtraeme 4f2a32a138 Remove neticp (network info commpage) stuff that dyoung added
accidentally to make this build again.
2008-02-07 04:44:21 +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
dyoung d8e12ce795 Fix more fall-out from extracting ifioctl_common(): don't return
ENETRESET from ifioctl().
2008-01-23 16:51:19 +00:00
dyoung aa385448f5 Functional: return ENTRESET from ifioctl_common(), if SIOCSIFCAP
changed anything.

Cosmetic: shorten staircase.
2008-01-22 22:26:30 +00:00
dyoung 94e4ecb4ba Add missing break statement. 2008-01-22 22:09:59 +00:00
dyoung 81e0f3dc3d Take two steps toward adding and deleting link-layer addresses.
1 Extract subroutine if_dl_create() from if_alloc_sadl().
  if_dl_create() allocates a link-layer ifaddr.

2 Extract subroutine ifioctl_common() from ifioctl().  ifioctl_common()
  will be the basis for an ifnet "superclass" whose functions
  drivers may inherit.  Very simple drivers may set ifnet->if_ioctl
  = ifioctl_common.  More sophisticated drivers will set ifnet->if_ioctl
  = driver_ioctl.  driver_ioctl() will call ifioctl_common() to
  re-use the common code.
2008-01-22 16:25:15 +00:00
dyoung 6f3852fab4 Constify struct ifnet->if_sadl and every use throughout the tree.
Add if_set_sadl() that both sets the link-layer address length and
replaces the current link-layer address with a new one, and use it
throughout the tree.
2007-12-20 21:08:17 +00:00
dyoung 72fa642a86 Poison struct route->ro_rt uses in the kernel by changing the name
to _ro_rt.  Use rtcache_getrt() to access a route cache's struct
rtentry *.

Introduce struct ifnet->if_dl that always points at the interface
identifier/link-layer address.  Make code that treated the first
ifaddr on struct ifnet->if_addrlist as the interface address use
if_dl, instead.

Remove stale debugging code from net/route.c.  Move the rtflush()
code into rtcache_clear() and delete rtflush().  Delete rtalloc(),
because nothing uses it any more.

Make ND6_HINT an inline, lowercase subroutine, nd6_hint.

I've done my best to convert IP Filter, the ISO stack, and the
AppleTalk stack to rtcache_getrt().  They compile, but I have not
tested them.  I have given the changes to PF, GRE, IPv4 and IPv6
stacks a lot of exercise.
2007-12-20 19:53:29 +00:00
dyoung 9fd5916940 Fix a serious regression: insert new ifaddrs at the end of if_addrlist,
not at the front, because the first ifaddr on the list has special
significance (grrr).
2007-12-06 02:23:42 +00:00
dyoung 7a3c43874a Add ifa_insert() and ifa_remove() that add/remove an ifaddr to/from
an interface and increase/decrease its reference count.
2007-12-06 00:23:09 +00:00
dyoung b8f324fabd Extract common code, creating a subroutine if_purgeaddrs(ifp,
family, purgeaddr) which applies function `purgeaddr' to each
address on `ifp' belonging to `family'.
2007-12-05 23:47:17 +00:00
dyoung adde197943 Use IFADDR_EMPTY(). 2007-12-05 22:51:01 +00:00
dyoung 73b0c685df Use IFADDR_FOREACH(). 2007-12-04 10:31:14 +00:00
dyoung 08fdf3b0de Change a few malloc(9) + memset(3) pairs to malloc(..., ...|M_ZERO). 2007-11-01 20:37:48 +00:00
dyoung 462deb7ea8 In ifreq_setaddr(), use the right buffer sizes for compat v.
non-compat commands.
2007-10-11 20:47:27 +00:00
gdt 2f4541505a Add a define for the ifru_space union member.
Copy the entire sockaddr to the buffer to be written to user space,
according to its length, not just the part that fits in struct
sockaddr.

This fixes the 'bad MAC address' problem in dhclient.
2007-09-13 18:54:57 +00:00
gdt aebe6f5793 Fix bug in SIOCGIFCONF where the wrong length was calculated for
sockaddrs bigger than struct sockaddr.  Tightly bind decrementing
available space and using it, avoiding incorrect accounting in an
error case.  Document invariants.  Document calling convention for
SIOCGIFCONF.  Simplify by removing code to handle sockaddrs that don't
fit in struct ifreq; with sockaddr_storage this can no longer occur.
Add several KASSERTs.

This commit resolves the problem with racoon failing to list
interfaces.

Proposed on tech-net@ with no objections.
2007-09-11 19:31:22 +00:00
dyoung 9bee2cd7f1 Fix compilation if !defined(INET6). Thanks, Geoff Wing, for the
bug report & patch.
2007-09-01 07:03:32 +00:00
dyoung 7e6b3f4292 Per discussion in 30 May 2007 on tech-net, add accessors for
ifreq->ifr_addr, ifreq_getaddr() and ifreq_setaddr().
2007-08-31 21:02:15 +00:00
dyoung b3fc296326 Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain.  Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.

Return sockaddr_dl to its "historical" size.  Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.

Avoid using sizeof(struct sockaddr_dl) in the kernel.

Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.

Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().

Constify: LLADDR() -> CLLADDR().

Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead.  Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
2007-08-30 02:17:34 +00:00
skd d4509b0376 Clean up net compat ioctls, and clean up handling of wireless ioctls. 2007-08-20 04:49:40 +00:00
dyoung 1cf606d23a In if_alloc_sadl(), use sockaddr_dl_init() and satocsdl(). Introduce
variable 'mask' for the netmask, and use it instead of assigning
to 'sdl' twice.

In ifa_ifwithnet(), use satocsdl().
2007-08-07 04:14:37 +00:00
dyoung 08e6f22226 Take steps to hide the radix_node implementation of the forwarding table
from the forwarding table's users:

        Introduce rt_walktree() for walking the routing table and
        applying a function to each rtentry.  Replace most
        rn_walktree() calls with it.

        Use rt_getkey()/rt_setkey() to get/set a route's destination.
        Keep a pointer to the sockaddr key in the rtentry, so that
        rtentry users do not have to grovel in the radix_node for
        the key.

        Add a RTM_GET method to rtrequest.  Use that instead of
        radix_node lookups in, e.g., carp(4).

Add sys/net/link_proto.c, which supplies sockaddr routines for
link-layer socket addresses (sockaddr_dl).

Cosmetic:

        Constify.  KNF.  Stop open-coding LIST_FOREACH, TAILQ_FOREACH,
        et cetera.  Use NULL instead of 0 for null pointers.  Use
        __arraycount().  Reduce gratuitous parenthesization.

        Stop using variadic arguments for rip6_output(), it is
        unnecessary.

        Remove the unnecessary rtentry member rt_genmask and the
        code to maintain it, since nothing actually used it.

        Make rt_maskedcopy() easier to read by using meaningful variable
        names.

        Extract a subroutine intern_netmask() for looking up a netmask in
        the masks table.

        Start converting backslash-ridden IPv6 macros in
        sys/netinet6/in6_var.h into inline subroutines that one
        can read without special eyeglasses.

One functional change: when the kernel serves an RTM_GET, RTM_LOCK,
or RTM_CHANGE request, it applies the netmask (if supplied) to a
destination before searching for it in the forwarding table.

I have changed sys/netinet/ip_carp.c, carp_setroute(), to remove
the unlawful radix_node knowledge.

Apart from the changes to carp(4), netiso, ATM, and strip(4), I
have run the changes on three nodes in my wireless routing testbed,
which involves IPv4 + IPv6 dynamic routing acrobatics, and it's
working beautifully so far.
2007-07-19 20:48:52 +00:00
ad 88ab7da936 Merge some of the less invasive changes from the vmlocking branch:
- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
2007-07-09 20:51:58 +00:00
dyoung 95edb940c2 Get rid of radix_node_head.rnh_walktree, because it is only ever
set to rn_walktree.

Introduce rt_walktree(), which applies a subroutine to every route
in a particular address family.  Use it instead of rn_walktree()
virtually everywhere.  This helps to hide the routing table
implementation.
2007-06-09 03:07:21 +00:00
christos 89734304c6 - fix unused variable when none of the compat options are defined.
- remove debugging
2007-06-01 15:41:15 +00:00
enami 723ff30abc Fix some bugs in ifconf():
- maintain space left correctly.  the pointer is advanced by the size
  of struct ifreq when length of address is small.
- single sizeof operator is enough to take the size of struct.
- the type of `sz' must be singed type since it is/was compared against to
  the variable which may become negative.
- no need to traverse rest of interfaces once we got an error.  note that
  the latter `break' statement was inside inner loop.
2007-06-01 09:35:47 +00:00
christos f6ca3502bf provide the minimum ifreq size (when sockaddr is empty) 2007-05-31 02:56:50 +00:00
christos d81aadc176 Move the nasty ifdefs in one place. Requested by ad and dyoung. 2007-05-30 21:02:02 +00:00
xtraeme 967c5e0168 Initialize oifr to fix build with COMPAT_40. 2007-05-29 22:05:01 +00:00
christos 20bfd9898e Add a sockaddr_storage member to "struct ifreq" maintaining backwards
compatibility with the older ioctls. This avoids stack smashing and
abuse of "struct sockaddr" when ioctls placed "struct sockaddr_foo's" that
were longer than "struct sockaddr".
XXX: Some of the emulations might be broken; I tried to add code for
them but I did not test them.
2007-05-29 21:32:27 +00:00
dyoung cafee584b5 KNF: compare pointers with NULL instead of 0, and do not "test
truth" of either integers or pointers, so that it's clear
     what's going on.  Remove superfluous () from return statements.
     bcmp -> memcmp, bcopy -> memcpy.

Misc. cosmetic: join some lines, remove a few empty lines, remove
spaces from type casts.  Don't open-code IFNET_FOREACH().  Shorten
some staircases.
2007-03-18 20:59:38 +00:00
dyoung 912b6eb53e The departure of IPv6 interfaces does not agree with pf. The pfil
hooks that signal the interface's departure run before IPv6 sends
messages to indicate that it is leaving its multicast groups; when
pf filters the departure messages, it does not recognize the output
interface, so it complains at the departure of gre65, for example:

pf_test6: kif == NULL, if_xname gre65

I have changed if_detach() so that it calls pr_usrreq(PRU_PURGEIF)
before pfil_run_hooks(PFIL_IFNET_DETACH), instead of the other way
around.  That quiets the pf_test6: messages.
2007-03-18 20:05:52 +00:00