Commit Graph

5791 Commits

Author SHA1 Message Date
Mike Makonnen
34a087543a Gcc barfs in glob.c when run with -O3. To fix this make g_strchr() work on
and return (const Char *) pointers instead of just (Char *) and get rid of
all the type casting.

PR:		kern/124334
2008-06-26 07:12:35 +00:00
Ruslan Ermilov
042df2e2da Enable GCC stack protection (aka Propolice) for userland:
- It is opt-out for now so as to give it maximum testing, but it may be
  turned opt-in for stable branches depending on the consensus.  You
  can turn it off with WITHOUT_SSP.
- WITHOUT_SSP was previously used to disable the build of GNU libssp.
  It is harmless to steal the knob as SSP symbols have been provided
  by libc for a long time, GNU libssp should not have been much used.
- SSP is disabled in a few corners such as system bootstrap programs
  (sys/boot), process bootstrap code (rtld, csu) and SSP symbols themselves.
- It should be safe to use -fstack-protector-all to build world, however
  libc will be automatically downgraded to -fstack-protector because it
  breaks rtld otherwise.
- This option is unavailable on ia64.

Enable GCC stack protection (aka Propolice) for kernel:
- It is opt-out for now so as to give it maximum testing.
- Do not compile your kernel with -fstack-protector-all, it won't work.

Submitted by:	Jeremie Le Hen <jeremie@le-hen.org>
2008-06-25 21:33:28 +00:00
Ed Schouten
c605eea952 Turn execvpe() into an internal libc routine.
Adding exevpe() has caused some ports to break. Even though execvpe() is
a useful routine, it does not conform to any standards.

This patch is a little bit different from the patch sent to the mailing
list. I forgot to remove execvpe from the Symbol.map (which does not
seem to miscompile libc, though).

Reviewed by:	davidxu
Approved by:	philip
2008-06-23 05:22:06 +00:00
Poul-Henning Kamp
20067a6892 Add Xr to getsockname(2) 2008-06-20 14:47:06 +00:00
David Xu
8e9a8a6c78 Process spawn attributes in POSIX document order. 2008-06-19 02:42:50 +00:00
Ed Schouten
e3580e9d91 Don't export the unused __use_pts() routine.
The __use_pts() routine was once probably used by libutil to determine
if we are using BSD or UNIX98 style PTY device names. It doesn't seem to
be used outside grantpt.c, which means we can make it static and remove
it from the Symbol.map.

Reviewed by:	cognet, kib
Approved by:	philip (mentor)
2008-06-17 14:05:03 +00:00
David Xu
fdbeb80a2b Style fix. 2008-06-17 08:23:45 +00:00
Ed Schouten
d1b2bd213c Change my email address to the one from the FreeBSD project.
Approved by:	philip (mentor, implicit), davidxu
2008-06-17 07:09:58 +00:00
David Xu
947aa542e9 Add POSIX routines called posix_spawn() and posix_spawnp(), which
can be used as replacements for exec/fork in a lot of cases. This
change also added execvpe() which allows environment variable
PATH to be used for searching executable file, it is used for
implementing posix_spawnp().

PR: standards/122051
2008-06-17 06:26:29 +00:00
Tony Finch
0cf1d3bf73 Make it clearer that privilege is needed to reduce as well as
increase group membership.
2008-06-16 14:50:21 +00:00
Wojciech A. Koszek
98fbfcd632 Bring missing getsockopt(2) options: SO_LABEL SO_PEERLABEL SO_LISTENQLIMIT
SO_LISTENQLEN SO_LISTENINCQLEN to the manual page.

Till now those were only present in sys/socket.h file.

Reviewed by:	rwatson, gnn, keramida (with mdoc hat)
2008-06-12 22:58:35 +00:00
Jason Evans
b1c8b30f55 In the error path through base_alloc(), release base_mtx [1].
Fix bit vector initialization for run headers.

Submitted by:	[1] Mike Schuster <schuster@adobe.com>
2008-06-10 15:46:18 +00:00
David Xu
83a0758789 Make pthread_cleanup_push() and pthread_cleanup_pop() as a pair of macros,
use stack space to keep cleanup information, this eliminates overhead of
calling malloc() and free() in thread library.

Discussed on: thread@
2008-06-09 01:14:10 +00:00
Doug Rabson
cd7d66a21f Call the fcntl compatiblity wrapper from the thread library fcntl wrappers
so that they get the benefit of the (limited) forward ABI compatibility.

MFC after: 1 week
2008-05-30 14:47:42 +00:00
Doug Rabson
2da0808aec Make fcntl() a weak symbol so that it can be overridden by thread libraries.
MFC after: 2 days
2008-05-27 14:03:32 +00:00
Greg Lehey
b98d401185 Clarify that "ante meridiem" and "post meridiem" mean the same thing
as the more commonly used "a.m." and "p.m.".

Tripped over by:  Callum Gibson.

MFC after:  2 weeks
2008-05-16 04:33:04 +00:00
Jason Evans
2e78350530 Clean up cpp logic and comments. 2008-05-14 18:33:13 +00:00
Antoine Brodin
27522528ea Remove useless call to getdtablesize(2) in fdopen(3) and its useless
variable nofile.

PR:		123109
Submitted by:	Christoph Mallon
Approved by:	rwatson (mentor)
MFC after:	1 month
2008-05-10 18:39:20 +00:00
Christian Brueffer
2e462358ed Misc mdoc improvements and a typo fix. 2008-05-10 07:31:34 +00:00
Julian Elischer
4ba9fdc4a6 Add setfib.2 to the list of man pages to add 2008-05-09 23:09:56 +00:00
Julian Elischer
23c3fd9e62 setfib.2 got left out of the last commit 2008-05-09 23:08:40 +00:00
Julian Elischer
65cb6b6834 Add code to allow the system to handle multiple routing tables.
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

PR:
Reviewed by:	several including rwatson, bz and mlair (parts each)
Approved by:
Obtained from:	Ironport systems/Cisco
MFC after:
Security:

PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
MFC after:
Security:
2008-05-09 23:00:21 +00:00
Alexander Kabaev
5e29db42b9 Keep versions on a dependency chain to exclude even remote possiblity
of private version ever getting index 2.
2008-05-07 15:39:34 +00:00
Daniel Eischen
f3e9983ea6 Add a comment stating not to bump the FBSDprivate version.
Don't inherit the public namespace from the private namespace.
2008-05-06 01:41:55 +00:00
John Baldwin
143b946188 Retire the __fgetcookie(), __fgetpendout(), and __fsetfileno() accessors
as we aren't hiding FILE's internals anymore.
2008-05-05 16:14:02 +00:00
John Baldwin
19e03ca803 Expose FILE's internals to the world again in all their glory. Restore
all the previous inline optimizations as well.  FILE is back to using
__mbstate_t, struct pthread *, and struct pthread_mutex *.
2008-05-05 16:03:52 +00:00
Konstantin Belousov
90c68c1799 Do not read away the target directory entry when encountering deleted
files after a seekdir().

The seekdir shall set the position for the next readdir operation.
When the _readdir_unlocked() encounters deleted entry, dd_loc is
already advanced. Continuing the loop leads to premature read of
the target entry.

Submitted by:	Marc Balmer <mbalmer at openbsd org>
Obtained from:	OpenBSD
MFC after:	2 weeks
2008-05-05 14:05:23 +00:00
Marcel Moolenaar
201e72e716 Add __fgetcookie(), __fgetpendout() and __fsetfileno() to the private
name space.
2008-05-04 04:11:01 +00:00
Marcel Moolenaar
0aca787a7b Unbreak build: gnu sort has been configured to grope inside struct
__sFILE. It's opaque now, so add a function that returns the pending
output bytes.

Pointy hat: jhb
2008-05-03 23:36:00 +00:00
Marcel Moolenaar
430f2c8721 Unbreak build: libftpio gropes inside struct __sFILE. Implement
accessor functions for its benefit now thaat FILE is opaque.
I'm sure there's a better way. I leave that for people to work
on in a src tree that isn't broken.

Pointy hat: jhb
2008-05-03 20:09:44 +00:00
Jason Evans
4788234366 Fix a comment. 2008-05-03 17:49:16 +00:00
John Baldwin
c17bf9a9a5 Next round of stdio changes: Remove all inlining of stdio operations and
move the definition of the type backing FILE (struct __sFILE) into an
internal header.
- Remove macros to inline certain operations from stdio.h.  Applications
  will now always call the functions instead.
- Move the various foo_unlocked() functions from unlocked.c into foo.c.
  This lets some of the inlining macros (e.g. __sfeof()) move into
  foo.c.
- Update a few comments.
- struct __sFILE can now go back to using mbstate_t, pthread_t, and
  pthread_mutex_t instead of knowing about their private, backing types.

MFC after:	1 month
Reviewed by:	kan
2008-05-02 15:25:07 +00:00
John Baldwin
ab9306707a Include libc_private.h for the declaration of __isthreaded instead of
relying on namespace pollution in stdio.h.

MFC after:	3 days
2008-05-02 14:51:22 +00:00
Jason Evans
9007109030 Add a separate tree to track arena chunks that contain dirty pages.
This substantially improves worst case allocation performance, since
O(lg n) tree search can be used instead of O(n) tree iteration.

Use rb_wrap() instead of directly calling rb_*() macros.
2008-05-01 17:25:55 +00:00
Jason Evans
21162484ae Add rb_wrap(), which creates C function wrappers for most rb_*()
macros.

Add rb_foreach_next() and rb_foreach_reverse_prev(), which make it
possible to re-synchronize tree iteration after the tree has been
modified.

Rename rb_tree_new() to rb_new().
2008-05-01 17:24:37 +00:00
Oleksandr Tymoshenko
dfe2d491c0 o Add MIPS to the list of architectures with defined TLS_TCB_ALIGN
o Stick with TLS Variant II for MIPS for the moment.

  Approved by:	imp
2008-04-29 23:15:23 +00:00
Oleksandr Tymoshenko
00fb5362ba Set QUANTUM_2POW_MIN and SIZEOF_PTR_2POW parameters for MIPS
Approved by: imp
2008-04-29 22:56:05 +00:00
Jason Evans
e3085308be Check for integer overflow before calling sbrk(2), since it uses a
signed increment argument, but the size is an unsigned integer.
2008-04-29 01:32:42 +00:00
Robert Watson
7ee52b008a Correct minor typos in SCTP man pages.
MFC after:	3 days
2008-04-28 16:57:56 +00:00
Marcel Moolenaar
b0735d8073 Add support files for compiling with soft-float. This has been
copied from ARM and modified to warrant the duplication. Oh,
and to make it work for PowerPC :-)
2008-04-27 18:34:34 +00:00
Warner Losh
4ce261061f Add mips support libc from the mips2-jnpr branch of perforce. 2008-04-26 12:08:02 +00:00
Sean Farley
4bc1fa7662 Have the man page catch up with the namespace pollution cleanup that
occurred between 2001-2003.  Thanks to bde for the history lesson[1]
concerning sys/types.h and the many system calls that at one time
(pre-2001) were required by POSIX to include it.

1. http://lists.freebsd.org/pipermail/freebsd-arch/2008-April/008126.html

MFC after:	3 days
2008-04-26 02:33:53 +00:00
Ruslan Ermilov
eff93c8073 Stricter check for integer overflow. 2008-04-24 07:49:00 +00:00
Jason Evans
e5bf0d71c9 Implement red-black trees without using parent pointers, and store the
color bit in the least significant bit of the right child pointer, in
order to reduce red-black tree linkage overhead by ~2X as compared to
sys/tree.h.

Use the new red-black tree implementation in malloc, which drops
memory usage by ~0.5 or ~1%, for 32- and 64-bit systems, respectively.
2008-04-23 16:09:18 +00:00
John Baldwin
bc669a8c33 Fix a leak in the recent fixes for file descriptors > SHRT_MAX. In the
case of a file descriptor we can't handle, clear the FILE structure's flags
so it can be reused.

MFC after:	1 week
Reported by:	otto @ OpenBSD
2008-04-22 17:03:32 +00:00
Antoine Brodin
88ff5136d1 Document that you must include <sys/param.h> before <sys/cpuset.h>.
Approved by:	rwatson (mentor)
2008-04-20 15:51:56 +00:00
Ruslan Ermilov
5b30d6ca77 Don't forget to free() currency_symbol and asciivalue when multiple
conversion specifiers for them are present.

Submitted by:	Maxim Dounin <mdounin@mdounin.ru>
Obtained from:	NetBSD (partially)
MFC after:	3 days
2008-04-19 07:22:58 +00:00
Ruslan Ermilov
3890416f9c Better strfmon(3) conversion specifiers sanity checking.
There were no checks for left and right precisions at all, and
a check for field width had integer overflow bug.

Reported by:	Maksymilian Arciemowicz
Security:	http://securityreason.com/achievement_securityalert/53
Submitted by:	Maxim Dounin <mdounin@mdounin.ru>
MFC after:	3 days
2008-04-19 07:18:22 +00:00
John Baldwin
1e98f88776 Next stage of stdio cleanup: Retire __sFILEX and merge the fields back into
__sFILE.  This was supposed to be done in 6.0.  Some notes:
- Where possible I restored the various lines to their pre-__sFILEX state.
- Retire INITEXTRA() and just initialize the wchar bits (orientation and
  mbstate) explicitly instead.  The various places that used INITEXTRA
  didn't need the locking fields or _up initialized.  (Some places needed
  _up to exist and not be off the end of a NULL or garbage pointer, but
  they didn't require it to be initialized to a specific value.)
- For now, stdio.h "knows" that pthread_t is a 'struct pthread *' to
  avoid namespace pollution of including all the pthread types in stdio.h.
  Once we remove all the inlines and make __sFILE private it can go back
  to using pthread_t, etc.
- This does not remove any of the inlines currently and does not change
  any of the public ABI of 'FILE'.

MFC after:	1 month
Reviewed by:	peter
2008-04-17 22:17:54 +00:00
Xin LI
6fda52ba75 Implement fdopendir(3) by splitting __opendir2() into two parts, the upper part
deals with the usual __opendir2() calls, and the rest part with an interface
translator to expose fdopendir(3) functionality.  Manual page was obtained from
kib@'s work for *at(2) system calls.
2008-04-16 18:59:36 +00:00