osquery-1/osquery/events/kernel.h

100 lines
2.5 KiB
C
Raw Normal View History

2015-06-30 21:16:43 +00:00
/*
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#pragma once
2015-08-16 03:43:53 +00:00
#include <vector>
2015-06-30 21:16:43 +00:00
#include <osquery/events.h>
#include <osquery/status.h>
2015-08-16 03:43:53 +00:00
#include "osquery/events/kernel/circular_queue_user.h"
2015-06-30 21:16:43 +00:00
namespace osquery {
2015-08-16 03:43:53 +00:00
/**
* @brief Name of the kernel communication device node.
*
* The kernel component creates an ioctl API for synchronizing kernel-based
* subscriptions and userland access to regions of shared memory.
*/
extern const std::string kKernelDevice;
2015-07-29 01:38:48 +00:00
/**
* @brief Load kernel extension if applicable.
*/
void loadKernelExtension();
2015-06-30 21:16:43 +00:00
/**
* @brief Subscription details for KernelEventPublisher events.
*/
struct KernelSubscriptionContext : public SubscriptionContext {
/// The kernel event subscription type.
osquery_event_t event_type;
/// Optional category passed to the callback.
std::string category;
2015-06-30 21:16:43 +00:00
};
/**
* @brief Event details for a KernelEventPubliser events.
*/
struct KernelEventContext : public EventContext {
/// The event type.
osquery_event_t event_type;
2015-06-30 21:20:04 +00:00
/// The observed uptime of the system at event time.
uint32_t uptime{0};
2015-06-30 21:16:43 +00:00
};
template <typename EventType>
struct TypedKernelEventContext : public KernelEventContext {
EventType event;
// The flexible data must remain as the last member.
std::vector<char> flexible_data;
2015-06-30 21:16:43 +00:00
};
using KernelSubscriptionContextRef = std::shared_ptr<KernelSubscriptionContext>;
using KernelEventContextRef = std::shared_ptr<KernelEventContext>;
2015-06-30 21:16:43 +00:00
template <typename EventType>
using TypedKernelEventContextRef =
std::shared_ptr<TypedKernelEventContext<EventType> >;
2015-06-30 21:16:43 +00:00
class KernelEventPublisher
: public EventPublisher<KernelSubscriptionContext, KernelEventContext> {
DECLARE_PUBLISHER("kernel");
public:
KernelEventPublisher() : EventPublisher(), queue_(nullptr){};
Status setUp() override;
void configure() override;
2015-06-30 21:16:43 +00:00
void tearDown() override;
2015-06-30 21:16:43 +00:00
Status run() override;
2015-06-30 21:16:43 +00:00
private:
CQueue *queue_{nullptr};
2015-06-30 21:16:43 +00:00
/// Check whether the subscription matches the event.
bool shouldFire(const KernelSubscriptionContextRef &sc,
const KernelEventContextRef &ec) const override;
2015-06-30 21:16:43 +00:00
template <typename EventType>
KernelEventContextRef createEventContextFrom(osquery_event_t event_type,
2015-06-30 21:20:04 +00:00
CQueue::event *event) const;
2015-06-30 21:16:43 +00:00
};
} // namespace osquery