Commit Graph
68 Commits
Author SHA1 Message Date
Tobias Brunner f6aafb3005 Fixed some typos, courtesy of codespell
Main change is the conversion from the British cancelling/-ed to the
American canceling/-ed.
2021-06-25 11:32:29 +02:00
Tobias Brunner aaa908dc0a scheduler: Use timercmp(3) instead of a custom function 2020-06-02 14:07:06 +02:00
Josh Soref b3ab7a48cc Spelling fixes
* accumulating
* acquire
* alignment
* appropriate
* argument
* assign
* attribute
* authenticate
* authentication
* authenticator
* authority
* auxiliary
* brackets
* callback
* camellia
* can't
* cancelability
* certificate
* choinyambuu
* chunk
* collector
* collision
* communicating
* compares
* compatibility
* compressed
* confidentiality
* configuration
* connection
* consistency
* constraint
* construction
* constructor
* database
* decapsulated
* declaration
* decrypt
* derivative
* destination
* destroyed
* details
* devised
* dynamic
* ecapsulation
* encoded
* encoding
* encrypted
* enforcing
* enumerator
* establishment
* excluded
* exclusively
* exited
* expecting
* expire
* extension
* filter
* firewall
* foundation
* fulfillment
* gateways
* hashing
* hashtable
* heartbeats
* identifier
* identifiers
* identities
* identity
* implementers
* indicating
* initialize
* initiate
* initiation
* initiator
* inner
* instantiate
* legitimate
* libraries
* libstrongswan
* logger
* malloc
* manager
* manually
* measurement
* mechanism
* message
* network
* nonexistent
* object
* occurrence
* optional
* outgoing
* packages
* packets
* padding
* particular
* passphrase
* payload
* periodically
* policies
* possible
* previously
* priority
* proposal
* protocol
* provide
* provider
* pseudo
* pseudonym
* public
* qualifier
* quantum
* quintuplets
* reached
* reading
* recommendation to
* recommendation
* recursive
* reestablish
* referencing
* registered
* rekeying
* reliable
* replacing
* representing
* represents
* request
* request
* resolver
* result
* resulting
* resynchronization
* retriable
* revocation
* right
* rollback
* rule
* rules
* runtime
* scenario
* scheduled
* security
* segment
* service
* setting
* signature
* specific
* specified
* speed
* started
* steffen
* strongswan
* subjectaltname
* supported
* threadsafe
* traffic
* tremendously
* treshold
* unique
* uniqueness
* unknown
* until
* upper
* using
* validator
* verification
* version
* version
* warrior

Closes strongswan/strongswan#164.
2020-02-11 18:23:07 +01:00
Tobias Brunner 1b67166921 Unify format of HSR copyright statements 2018-05-23 16:32:53 +02:00
Tobias Brunner 2db6d5b8b3 Fixed some typos, courtesy of codespell 2018-02-13 12:19:54 +01:00
Tobias Brunner 0d08959a04 watcher: Don't notify watcher if removed FD was not found
This can happen if a stream is used blocking exclusively (the FD is
never registered with watcher, but is removed in the stream's destructor
just in case it ever was - doing this conditionally would require an
additional flag in streams).  There may be no thread reading from
the read end of the notify pipe (e.g. in starter), causing the write
to the notify pipe to block after it's full.  Anyway, doing a relatively
expensive FD update is unnecessary if there were no changes.

Fixes #1453.
2017-10-10 11:13:53 +02:00
Tobias Brunner 83eacc448c processor: Move priority threads assignment to set_threads()
This avoids the evaluation of %N even if the thread pool is never used.
We need to avoid as many custom printf specifiers as possible when
fuzzing our code to avoid excessive log messages.
2017-05-23 18:29:12 +02:00
Tobias Brunner b27663399b watcher: Avoid allocations due to enumerators
Since the FD set could get rebuilt quite often this change avoids having
to allocate memory just to enumerate the registered FDs.
2016-10-04 10:12:18 +02:00
Andreas Steffen b12c53ce77 Use standard unsigned integer types 2016-03-24 18:52:48 +01:00
Martin Willi 8b0c9cf155 watcher: Check for cancellation if poll() fails with EINTR
With LinuxThreads, poll() is unfortunately no cancellation point. It seems
that poll gets woken up after cancellation, but we actively must check
for cancellation before re-entering poll to properly shut down the watcher
thread.
2015-12-04 08:01:15 +01:00
Tobias Brunner 11ac1dff9c scheduler: Add method to remove all scheduled jobs
References #840.
2015-03-09 15:57:57 +01:00
Martin Willi 04337fed02 apple: Redefine some additional clashing Mach types
While they usually are not included in a normal strongSwan build, the XPC
header indirectly defines these Mach types. To build charon-xpc, which uses
both XPC and strongSwan includes, we have to redefine these types.
2014-12-16 17:22:28 +01:00
Martin Willi 015fb3134d watcher: Proper handle poll() POLLHUP/NVAL signaling
poll() may return POLLHUP or POLLNVAL for given file descriptors. To handle
these properly, we signal them to the EXCEPT watcher state, if registered. If
not, we call the read/write callbacks, so they can properly fail when trying
to read from or write to the file descriptor.
2014-11-28 12:50:34 +01:00
Martin Willi 6e1d3f3615 watcher: Use Windows read/write(2) wrappers instead of compile-conditions 2014-11-21 12:02:08 +01:00
Martin Willi 03bccc240c watcher: Use poll(2) instead of select 2014-11-21 12:02:07 +01:00
Tobias Brunner 4bae9ec8d1 watcher: Doxygen comment fixed 2014-10-13 16:56:30 +02:00
Martin Willi 5ea627bdfa watcher: Add a method to query the watcher state
This allows a user to check if the watcher is actually running, and potentially
perform read operations directly instead of relying on watcher.
2014-09-24 11:19:59 +02:00
Martin Willi bc1139480f watcher: Prevent race condition spawning multiple watcher threads
If file descriptors get added and removed in rapid succession, the active
watcher thread might not take notice of it and continues running. However, add()
spawns a watcher thread whenever a file descriptor is added to an empty set.
This could result in multiple watcher threads, which is fixed by a proper
check for running watchers.
2014-06-17 15:19:47 +02:00
Martin Willi 93f78d8225 watcher: Add Windows support
Instead of a pipe we use a TCP socketpair (can't select() a _pipe()), and
Windsock2 send/recv functions instead of read/write.

Currently supported (and required) are file descriptors provided by Winsock
only; we might use a separate mechanism for traditional file handles if
required (or switch to Windows events and WaitForMultipleObjects) for a future
version.
2014-06-04 15:52:59 +02:00
Martin Willi d2b07d3187 watcher: Don't wait for running callback once watcher thread cancelled
During shutdown, waiting for callbacks might never complete, as queued
callbacks might not get executed under certain conditions. Not the clean fix,
but works good enough for now.

Seen on Windows in vici tests.
2014-05-07 14:13:34 +02:00
Martin Willi d16d5a245f watcher: Avoid queueing multiple watcher callbacks at the same time
While we don't add FDs with an active callback to the watched FDSET, we still
can get notifications for callbacks active due the asynchronous processing
of the same.

To avoid queue multiple callbacks, we check for queued callbacks before
activating new ones.
2014-05-07 14:13:34 +02:00
Martin Willi 874e212f71 processor: Flush pending jobs during cancel(), not destroy
During shutdown, cancel queued jobs earlier to avoid having cleanup functions
accessing infrastructure not available anymore, for example watcher.
2014-05-07 14:13:34 +02:00
Tobias Brunner 8dc6e71632 lib: All settings use configured namespace 2014-02-12 14:34:32 +01:00
Martin Willi 027cf7ddcf watcher: Don't complain if select() syscall got interrupted 2014-01-22 15:34:53 +01:00
Martin Willi 5ce3c9b15a watcher: Rebuild fdset when select() fails
This should make sure we refresh the fdset if a user closes an FD it just
removed. Some selects() seem to complain about the bad FD before signaling the
notification pipe.
2013-10-24 15:37:20 +02:00
Tobias Brunner 1f2d9c7688 watcher: Made notify array initialization compatible with older GCC versions 2013-07-25 16:57:42 +02:00
Martin Willi dcd5129c25 processor: force synchronous execute_job() if set_threads(0) has been called
During daemon shutdown, some idle threads might be lingering around even if
set_threads(0) already has been called. To avoid any races, we enforce
synchronous execution of the job.
2013-07-19 15:30:22 +02:00
Tobias Brunner 0ceb288815 Fix various API doc issues and typos
Partially based on an old patch by Adrian-Ken Rueegsegger.
2013-07-18 18:30:36 +02:00
Martin Willi 1897dd730f processor: remove the now unused get_threads() method again 2013-07-18 16:00:31 +02:00
Martin Willi ea009869e9 watcher: use processors new execute_job() to notify FDs
Just queueing is problematic, as all threads might be busy waiting for events
that the queued (but never executed) job delivers.
2013-07-18 16:00:31 +02:00
Martin Willi 6653e6c13e processor: add an execute_job() method to directly execute an important job
If all worker threads are busy and waiting for an event, we must ensure that
a job delivering that event gets executed. This new method has this property
for CRITICAL jobs, using a worker if we have one, but executing the job directly
if not.
2013-07-18 16:00:31 +02:00
Martin Willi 55240835b0 watcher: properly support multiple watch callback types for the same FD 2013-07-18 16:00:31 +02:00
Martin Willi d0c25a3f23 watcher: read multiple notifications if available
Use non-blocking I/O on the read end of the notify pipe. This also makes sure
the read does not block should select() signal data while there is none.
2013-07-18 16:00:31 +02:00
Martin Willi 58d0dadddc watcher: add some debugging statements 2013-07-18 16:00:29 +02:00
Martin Willi 91a2ae644c watcher: if the processor has no threads, execute the job with watcher thread
This is important during shutdown, where we might need to signal some FDs while
all idle threads are gone already.
2013-07-18 16:00:29 +02:00
Martin Willi 50720d7ce9 processor: add a getter for the threads passed to set_threads() 2013-07-18 16:00:29 +02:00
Martin Willi a0e3a7363f watcher: unregister a watcher FD if its thread gets cancelled 2013-07-18 16:00:29 +02:00
Martin Willi a558ba16f3 watcher: release threads waiting in remove() when watcher thread gets cancelled
During daemon shutdown, users might call remove() after processor.set_threads(0)
has been called. This gets problematic, as a watch event might be unable
to signal completion when no threads are available anymore. Work around this
issue by cancelling waiters once processor.cancel() has been called.
2013-07-18 16:00:29 +02:00
Martin Willi 32b2a5e04b watcher: add a centralized an generic facility to monitor file descriptors 2013-07-18 16:00:27 +02:00
Tobias Brunner b1b0cce396 processor: Simplified the main loop 2013-06-28 17:02:06 +02:00
Tobias Brunner 6ca25ccc04 processor: Don't hold the lock while destroying jobs
If a lock is held when queue_job() is called and the same lock is
required during the destruction of a job, holding the internal lock
in the processor while calling destroy() could result in a deadlock.
2013-06-28 17:02:05 +02:00
Tobias Brunner f05b427265 Moved debug.[ch] to utils folder 2012-10-24 16:00:51 +02:00
Tobias Brunner 12642a6831 Moved data structures to new collections subfolder 2012-10-24 16:00:49 +02:00
Tobias Brunner e0efd7c121 Make rescheduling a job more predictable
This avoids race conditions between calls to cancel() and jobs that like
to be rescheduled.  If jobs were able to reschedule themselves it would
theoretically be possible that two worker threads have the same job
assigned (the one currently executing the job and the one executing the
same but rescheduled job if it already is time to execute it), this means
that cancel() could be called twice for that job.

Creating a new job based on the current one and reschedule that is also
OK, but rescheduling itself is more efficient for jobs that need to be
executed often.
2012-06-25 17:49:12 +02:00
Tobias Brunner 26d77eb3e6 Centralized thread cancellation in processor_t
This ensures that no threads are active when plugins and the rest of the
daemon are unloaded.

callback_job_t was simplified a lot in the process as its main
functionality is now contained in processor_t.  The parent-child
relationships were abandoned as these were only needed to simplify job
cancellation.
2012-06-25 17:38:59 +02:00
Tobias Brunner 7fec83af28 Give processor_t more control over the lifecycle of a job
Jobs are now destroyed by the processor, but they are allowed to
reschedule themselves.  That is, parts of the reschedule functionality
already provided by callback_job_t is moved to the processor.  Not yet
fully supported is JOB_REQUEUE_DIRECT and canceling jobs.

Note: job_t.destroy() is now called not only for queued jobs but also
after execution or cancellation of jobs.  job_t.status can be used to
decide what to do in said method.
2012-06-25 17:10:28 +02:00
Tobias Brunner 052e0a17b8 Use wrapped semaphore in callback_job_t. 2012-05-02 14:45:38 +02:00
Tobias Brunner b24287c269 Log worker thread ID with two digits. 2011-12-16 16:44:38 +01:00
Tobias Brunner edad908792 Fixed compiler warnings regarding enum comparison.
Warnings like

  comparison of unsigned expression < 0 is always false

are reported with -Wextra when enum types that are compiled to an
unsigned type (which is up to the compiler) are checked for negativity.
2011-11-25 09:40:30 +01:00
Tobias Brunner f3bb1bd039 Fixed common misspellings.
Mostly found by 'codespell'.
2011-07-20 16:14:10 +02:00