SolarCapture C Bindings
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups
Files | Data Structures | Macros | Typedefs | Enumerations | Functions
SolarCapture API

Files

file  args.h
 sc_arg: An argument to a node's initialisation function.
 
file  attr.h
 sc_attr: Control optional behaviours and tunables.
 
file  declare_types.h
 This header is used to generate C type definitions and corresponding runtime type information for data structures that are shared by SolarCapture with other processes.
 
file  dlist.h
 sc_dlist: A doubly-linked list.
 
file  event.h
 sc_callback: Interface for event notification.
 
file  ext_node.h
 Interface for writing custom nodes.
 
file  ext_packet.h
 sc_packet: The representation of a packet or other data.
 
file  ext_packet_list.h
 sc_packet_list: A list of packets.
 
file  iovec.h
 sc_iovec_ptr: Supports iterating over a 'struct iovec'.
 
file  mailbox.h
 sc_mailbox: A means to pass packets from one thread to another.
 
file  misc.h
 Miscellaneous utility functions.
 
file  node.h
 sc_node: An object that processes packets.
 
file  object.h
 sc_object: Opaque object interface. Use this to pass all types of data that are not ints, doubles or char arrays (see SC_PARAM_INT, SC_PARAM_DBL and SC_PARAM_STR respectively for these).
 
file  pkt_pool.h
 sc_pool: A pool of packet buffers.
 
file  predicate.h
 sc_pkt_predicate: Interface for testing properties of packets.
 
file  session.h
 sc_session: A set of threads and other objects.
 
file  stream.h
 This header file defines sc_stream objects for directing packets to a sc_vi instance. A packet must match all the stream criteria for it to be directed by the stream to an sc_vi instance.
 
file  thread.h
 sc_thread: Representation of a thread in SolarCapture.
 
file  time.h
 Functions for managing time.
 
file  vi.h
 sc_vi: Supports receiving packets from the network.
 

Data Structures

struct  sc_arg
 Representation of an argument. Used by node init functions. More...
 
union  sc_arg.val
 
struct  sc_dlist
 Doubly linked list pointers. More...
 
struct  sc_callback
 A callback object. More...
 
struct  sc_node
 Description of a node. More...
 
struct  sc_node_factory
 Struct to hold information about how to create an instance of this node. More...
 
struct  sc_node_type
 Describes a type of node. More...
 
struct  sc_packet
 Representation of a packet. More...
 
struct  sc_packet_list
 A list of packets or packet buffers. More...
 
struct  sc_iovec_ptr
 
struct  sc_pkt_predicate
 A packet predicate object. More...
 
struct  sc_session_error
 A SolarCapture session error object returned by sc_session_error_get. More...
 
struct  sc_attr
 Attribute object. More...
 
struct  sc_object
 An opaque object. Use this to pass all types of data that are not ints, doubles or char arrays (see SC_PARAM_INT, SC_PARAM_DBL and SC_PARAM_STR respectively for these) to nodes. More...
 
struct  sc_vi
 A VI object. More...
 

Macros

#define SC_ARG_INT(_name, _val)   { .name = _name, .type = SC_PARAM_INT, .val.i = _val }
 
#define SC_ARG_STR(_name, _val)   { .name = _name, .type = SC_PARAM_STR, .val.str = _val }
 
#define SC_ARG_OBJ(_name, _val)   { .name = _name, .type = SC_PARAM_OBJ, .val.obj = _val }
 
#define SC_ARG_DBL(_name, _val)   { .name = _name, .type = SC_PARAM_DBL, .val.dbl = _val }
 
#define ST_CONSTANT(name, val)   enum { name = val };a
 A constant value in the template definition. More...
 
#define ST_STRUCT(name)   struct name {
 Start of the template definition. More...
 
#define ST_FIELD_STR(name, len, kind)   char name[len];
 A string field in the template definition. More...
 
#define ST_FIELD(type, name, kind)   type name;
 A C basic type field in the template definition. More...
 
#define ST_STRUCT_END   };
 End of the template definition.
 
#define SC_CONTAINER(c_type, mbr_name, p_mbr)   ( (c_type*) ((char*)(p_mbr) - SC_MEMBER_OFFSET(c_type, mbr_name)) )
 Fetch a pointer to the outer container of a given sc_dlist pointer. More...
 
#define SC_DLIST_FOR_EACH_OBJ(list, iter, mbr)
 Create a for statement that loops over each container item in the list. It is not safe to modify the list using this macro, if list modifications are required see SC_DLIST_FOR_EACH_OBJ_SAFE. More...
 
#define SC_DLIST_FOR_EACH_OBJ_SAFE(list, iter, next_entry, mbr)
 Create a for statement that loops over each container item in the list which can be safely be modified during traversal. More...
 
#define sc_node_set_error(node, errno_code,...)
 Set error from within the implementation of a node. More...
 
#define sc_node_fwd_error(node, rc)   __sc_node_fwd_error((node), __FILE__, __LINE__, __func__, (rc))
 Forward error from a failed sc call. More...
 
#define SC_MEMBER_OFFSET(c_type, mbr_name)   ((uint32_t) (uintptr_t)(&((c_type*)0)->mbr_name))
 Calculate memory offset of a field within a struct. More...
 
#define SC_MEMBER_SIZE(c_type, mbr_name)   (sizeof(((c_type*)0)->mbr_name))
 Calculate the size of a field within a struct. More...
 
#define SC_FRAME_LEN_LARGE   UINT16_MAX
 struct sc_packet.frame_len holds this special value to indicate that the frame is "large". (Meaning it would overflow sc_packet.frame_len).
 
#define SC_CSUM_ERROR   (1 << 0)
 struct sc_packet.flags will have this set if the packet has a checksum error
 
#define SC_CRC_ERROR   (1 << 1)
 struct sc_packet.flags will have this set if the packet has a crc error
 
#define SC_TRUNCATED   (1 << 2)
 struct sc_packet.flags will have this set if the packet has been truncated
 
#define SC_MCAST_MISMATCH   (1 << 3)
 struct sc_packet.flags will have this set if the packet is for a multicast group the host hasn't joined
 
#define SC_UCAST_MISMATCH   (1 << 4)
 struct sc_packet.flags will have this set if the packet is for a unicast address not matching the host's
 

Typedefs

typedef void( sc_callback_handler_fn )(struct sc_callback *, void *event_info)
 A callback handler function. More...
 
typedef int( sc_node_init_fn )(struct sc_node *node, const struct sc_attr *attr, const struct sc_node_factory *)
 Signature of function to initialise a node. More...
 
typedef int( sc_node_prep_fn )(struct sc_node *node, const struct sc_node_link *const *links, int n_links)
 Signature of nt_prep_fn function. More...
 
typedef void( sc_node_pkts_fn )(struct sc_node *node, struct sc_packet_list *packet_list)
 Signature of nt_pkts_fn function. More...
 
typedef int( sc_node_add_link_fn )(struct sc_node *from_node, const char *link_name, struct sc_node *to_node, const char *to_name_opt)
 Signature of nt_add_link_fn function. More...
 
typedef struct sc_node *( sc_node_select_subnode_fn )(struct sc_node *node, const char *name, char **new_name_out)
 Signature of nt_select_subnode_fn function. More...
 
typedef void( sc_node_end_of_stream_fn )(struct sc_node *node)
 Signature of nt_end_of_stream_fn function. More...
 
typedef int( sc_pkt_predicate_test_fn )(struct sc_pkt_predicate *, struct sc_packet *)
 

Enumerations

enum  sc_param_type { SC_PARAM_STR, SC_PARAM_INT, SC_PARAM_OBJ, SC_PARAM_DBL }
 Possible parameter types that can be used for arguments in a node's init function. More...
 
enum  sc_object_type { SC_OBJ_ANY, SC_OBJ_OPAQUE, SC_OBJ_PKT_PREDICATE }
 The type of data the sc_object contains. More...
 

Functions

int sc_attr_alloc (struct sc_attr **attr_out)
 Allocate an attribute object. More...
 
void sc_attr_free (struct sc_attr *attr)
 Free an attribute object. More...
 
void sc_attr_reset (struct sc_attr *attr)
 Return attributes to their default values. More...
 
int sc_attr_set_int (struct sc_attr *attr, const char *name, int64_t val)
 Set an attribute to an integer value. More...
 
int sc_attr_set_str (struct sc_attr *attr, const char *name, const char *s)
 Set an attribute to a string value. More...
 
int sc_attr_set_from_str (struct sc_attr *attr, const char *name, const char *val)
 Set an attribute to a string value. More...
 
struct sc_attrsc_attr_dup (const struct sc_attr *attr)
 Duplicate an attribute object. More...
 
int sc_attr_doc (const char *attr_name_opt, const char ***docs_out, int *docs_len_out)
 Returns documentation for attributes. Used by solar_capture_doc. More...
 
static void sc_dlist_init (struct sc_dlist *list)
 Initialise a pre-allocated sc_dlist to be an empty doubly linked list. More...
 
static int sc_dlist_is_empty (const struct sc_dlist *list)
 Check if a doubly linked list is empty, returns 1 if true 0 otherwise.
 
static void sc_dlist_push_head (struct sc_dlist *list, struct sc_dlist *l)
 Prepend an item to the head of a doubly-linked list. More...
 
static void sc_dlist_push_tail (struct sc_dlist *list, struct sc_dlist *l)
 Append an item to the tail of a doubly-linked list. More...
 
static void sc_dlist_remove (struct sc_dlist *l)
 Remove an item from the list. More...
 
static struct sc_dlistsc_dlist_pop_head (struct sc_dlist *list)
 Pop off the head of a list. More...
 
static struct sc_dlistsc_dlist_pop_tail (struct sc_dlist *list)
 Pop the tail of a list. More...
 
int sc_callback_alloc (struct sc_callback **cb_out, const struct sc_attr *attr, struct sc_thread *thread)
 Allocate a callback object instance. More...
 
void sc_callback_free (struct sc_callback *cb)
 Free a callback object instance. More...
 
static int sc_callback_is_active (const struct sc_callback *cb)
 Returns true if a callback object is active. More...
 
static void sc_callback_remove (struct sc_callback *cb)
 Unregister a callback object from its event source. More...
 
void sc_callback_on_idle (struct sc_callback *cb)
 Request a callback when the thread is idle. More...
 
int sc_epoll_ctl (struct sc_thread *thread, int op, int fd, unsigned events, struct sc_callback *cb)
 Request a callback when the thread is idle. More...
 
int sc_node_type_alloc (struct sc_node_type **nt_out, const struct sc_attr *attr_opt, const struct sc_node_factory *factory)
 Allocate an sc_node_type instance. More...
 
void sc_forward_list (struct sc_node *node, const struct sc_node_link *link, struct sc_packet_list *pl)
 Forward a list of packets. More...
 
void sc_forward (struct sc_node *node, const struct sc_node_link *link, struct sc_packet *packet)
 Forward a single packet. More...
 
int sc_node_init_get_arg_int (int *v_out, struct sc_node *node, const char *name, int v_default)
 Get an integer argument. More...
 
int sc_node_init_get_arg_str (const char **v_out, struct sc_node *node, const char *name, const char *v_default)
 Get an string argument. More...
 
int sc_node_init_get_arg_obj (struct sc_object **obj_out, struct sc_node *node, const char *name, enum sc_object_type obj_type)
 Get an sc_object argument. More...
 
int sc_node_init_get_arg_dbl (double *v_out, struct sc_node *node, const char *name, double v_default)
 Get a double argument. More...
 
const struct sc_node_linksc_node_prep_get_link (struct sc_node *node, const char *link_name)
 Find a named outgoing link. More...
 
const struct sc_node_linksc_node_prep_get_link_or_free (struct sc_node *node, const char *link_name)
 Find a named outgoing link or return a link for freeing. More...
 
int sc_node_prep_check_links (struct sc_node *node)
 Check the node's links for any unused links. More...
 
int sc_node_prep_get_pool (struct sc_pool **pool_out, const struct sc_attr *attr, struct sc_node *node, const struct sc_node_link *const *links, int n_links)
 Get a packet pool that can be used to obtain empty packet buffers that can be passed to any of the given set of links. More...
 
void sc_node_link_end_of_stream (struct sc_node *node, const struct sc_node_link *link)
 Indicate end-of-stream on a link. More...
 
int sc_node_export_state (struct sc_node *node, const char *type_name, int type_size, void *pp_area)
 Export dynamic state to solar_capture_monitor. More...
 
static int sc_packet_bytes (struct sc_packet *p)
 Return the size of the packet data in bytes. More...
 
static struct sc_packetsc_packet_frags_tail (struct sc_packet *p)
 Return a packet's last fragment. More...
 
static void sc_packet_prefetch_r (struct sc_packet *p)
 Prefetch a packet for reading. More...
 
static void sc_packet_prefetch_rw (struct sc_packet *p)
 Prefetch a packet for reading and writing. More...
 
static struct timespec sc_packet_timespec (const struct sc_packet *p)
 Return the timestamp of the packet in timespec format. More...
 
static void sc_packet_list_init (struct sc_packet_list *l)
 Initialise a list. More...
 
static int sc_packet_list_is_empty (const struct sc_packet_list *l)
 Check if packet list is empty. More...
 
static void sc_packet_list_finalise (struct sc_packet_list *l)
 Finalise a list. More...
 
static struct sc_packetsc_packet_list_tail (struct sc_packet_list *l)
 Return the tail of current tail of the list. More...
 
static void sc_packet_list_push_head (struct sc_packet_list *pl, struct sc_packet *p)
 Push a packet to the head of a list. More...
 
static void sc_packet_list_append (struct sc_packet_list *l, struct sc_packet *p)
 Append a packet to a list and finalise. More...
 
static void sc_packet_list_append_list (struct sc_packet_list *dest, struct sc_packet_list *src)
 Append a list to a list. More...
 
static struct sc_packetsc_packet_list_pop_head (struct sc_packet_list *pl)
 Remove and return the head of the list. More...
 
static void sc_iovec_ptr_init (struct sc_iovec_ptr *iovp, const struct iovec *iov, int iovlen)
 Initialise a struct sc_iovec_ptr. More...
 
static void sc_iovec_ptr_init_buf (struct sc_iovec_ptr *iovp, void *buf, int len)
 Initialise a struct sc_iovec_ptr with a contiguous buffer. More...
 
static void sc_iovec_ptr_init_packet (struct sc_iovec_ptr *iovp, const struct sc_packet *packet)
 Initialise a struct sc_iovec_ptr to point at packet data. More...
 
static int sc_iovec_ptr_bytes (const struct sc_iovec_ptr *iovp)
 Returns the number of bytes represented by an sc_iovec_ptr. More...
 
int sc_iovec_ptr_skip (struct sc_iovec_ptr *iovp, int bytes_to_skip)
 Skip forward over an iovec. More...
 
int sc_iovec_ptr_find_chr (const struct sc_iovec_ptr *iovp, int c)
 Find offset of character in iovec. More...
 
int sc_iovec_ptr_copy_out (void *dest, struct sc_iovec_ptr *iovp, int max_bytes)
 Copy data out of an sc_iovec_ptr. More...
 
static void sc_iovec_copy_from_end (void *dest_buf, const struct iovec *iov, int iovlen, int bytes)
 Copy data out of the end of a sc_iovec_ptr. More...
 
static void sc_iovec_trim_end (struct iovec *iov, uint8_t *iovlen, int bytes)
 Remove data from the end of an iovec. More...
 
int sc_mailbox_alloc (struct sc_mailbox **mb_out, const struct sc_attr *attr, struct sc_thread *thread)
 Allocate a mailbox. More...
 
int sc_mailbox_connect (struct sc_mailbox *mb1, struct sc_mailbox *mb2)
 Connect a pair of mailboxes. More...
 
int sc_mailbox_set_recv (struct sc_mailbox *mailbox, struct sc_node *node, const char *name_opt)
 Connect a mailbox to a node. More...
 
struct sc_nodesc_mailbox_get_send_node (struct sc_mailbox *mailbox)
 Return a mailbox's "send node". More...
 
int sc_mailbox_poll (struct sc_mailbox *mailbox, struct sc_packet_list *list)
 Poll a mailbox. More...
 
void sc_mailbox_send (struct sc_mailbox *mailbox, struct sc_packet *packet)
 Send a packet through a mailbox to another thread. More...
 
void sc_mailbox_send_list (struct sc_mailbox *mailbox, struct sc_packet_list *list)
 Send a list of packets through a mailbox to another thread. More...
 
int sc_join_mcast_group (struct sc_session *scs, const char *interface, const char *group)
 Join a multicast group. More...
 
int sc_node_alloc (struct sc_node **node_out, const struct sc_attr *attr, struct sc_thread *thread, const struct sc_node_factory *factory, const struct sc_arg *args, int n_args)
 Allocate a packet processing node. More...
 
int sc_node_alloc_named (struct sc_node **node_out, const struct sc_attr *attr, struct sc_thread *thread, const char *factory_name, const char *lib_name, const struct sc_arg *args, int n_args)
 Allocate a packet processing node by name. More...
 
int sc_node_add_link (struct sc_node *from_node, const char *link_name, struct sc_node *to_node, const char *to_name_opt)
 Add a link from one node to another. More...
 
struct sc_thread * sc_node_get_thread (const struct sc_node *node)
 Return the thread associated with a node. More...
 
int sc_node_factory_lookup (const struct sc_node_factory **factory_out, struct sc_session *session, const char *factory_name, const char *lib_name)
 Find a node factory. More...
 
void sc_node_add_info_str (struct sc_node *node, const char *field_name, const char *field_val)
 Export information to solar_capture_monitor. More...
 
void sc_node_add_info_int (struct sc_node *node, const char *field_name, int64_t field_val)
 Export information to solar_capture_monitor. More...
 
enum sc_object_type sc_object_type (struct sc_object *obj)
 Return the type of data contained within the sc_object. More...
 
int sc_opaque_alloc (struct sc_object **obj_out, void *opaque)
 Allocate memory for an opaque sc_object. More...
 
void sc_opaque_free (struct sc_object *obj)
 Free an sc_object previously allocated using sc_opaque_alloc. Only use this to free an opaque sc_object. The underlying data wrapped by this object will not be freed. More...
 
void sc_opaque_set_ptr (struct sc_object *obj, void *opaque)
 Set the opaque pointer in an sc_object. More...
 
void * sc_opaque_get_ptr (const struct sc_object *obj)
 Get the opaque pointer stored in an sc_object. More...
 
int sc_pool_get_packets (struct sc_packet_list *list, struct sc_pool *pool, int min_packets, int max_packets)
 Get packet buffers from a pool. More...
 
void sc_pool_return_packets (struct sc_pool *pool, struct sc_packet_list *list)
 Return packets to a pool. More...
 
void sc_pool_on_threshold (struct sc_pool *pool, struct sc_callback *event, int threshold)
 Request a callback when the pool is refilled. More...
 
struct sc_packetsc_pool_duplicate_packet (struct sc_pool *pool, struct sc_packet *packet, int snap)
 Duplicate a packet. More...
 
int sc_packet_append_iovec_ptr (struct sc_packet *packet, struct sc_pool *pool, struct sc_iovec_ptr *iovp, int snap)
 Append data to a packet. More...
 
int sc_pkt_predicate_alloc (struct sc_pkt_predicate **pred_out, int private_bytes)
 Allocate a packet predicate object. More...
 
struct sc_objectsc_pkt_predicate_to_object (struct sc_pkt_predicate *pred)
 Convert a sc_pkt_predicate into a sc_object. More...
 
struct sc_pkt_predicatesc_pkt_predicate_from_object (struct sc_object *obj)
 Convert a sc_object into a sc_pkt_predicate. More...
 
int sc_session_alloc (struct sc_session **scs_out, const struct sc_attr *attr)
 Allocate a SolarCapture session. More...
 
int sc_session_prepare (struct sc_session *scs)
 Prepare a SolarCapture session. More...
 
int sc_session_go (struct sc_session *scs)
 Start a SolarCapture session. More...
 
int sc_session_pause (struct sc_session *scs)
 Pause a SolarCapture session. More...
 
struct sc_session_errorsc_session_error_get (struct sc_session *scs)
 Returns an error from a SolarCapture session. More...
 
void sc_session_error_free (struct sc_session *scs, struct sc_session_error *err)
 Frees an error object. More...
 
int sc_stream_alloc (struct sc_stream **stream_out, const struct sc_attr *attr, struct sc_session *scs)
 Create a new stream object for this session. More...
 
int sc_stream_free (struct sc_stream *stream)
 Free a previously created stream. More...
 
int sc_stream_reset (struct sc_stream *stream)
 Remove all stream filters. More...
 
int sc_stream_set_str (struct sc_stream *stream, const char *str)
 Configure the stream to capture all packets matching the specified filter string. This is the preferred way of adding filters to a stream. More...
 
int sc_stream_all (struct sc_stream *stream)
 Configure this stream to capture all packets that haven't been caught by another stream. More...
 
int sc_stream_mismatch (struct sc_stream *stream)
 Configure this stream to capture all packets that haven't been caught by another stream and are not requested by the kernel network stack. More...
 
int sc_stream_ip_dest_hostport (struct sc_stream *stream, int protocol, const char *dhost, const char *dport)
 Configure this stream to capture all packets with the matching protocol, destination hostname and destination port. More...
 
int sc_stream_ip_source_hostport (struct sc_stream *stream, const char *shost, const char *sport)
 Configure this stream to capture all packets with the matching protocol, source hostname and source port. More...
 
int sc_stream_eth_dhost (struct sc_stream *stream, const uint8_t *mac_addr)
 Configure this stream to capture all packets with the matching destination MAC address. More...
 
int sc_stream_eth_vlan_id (struct sc_stream *stream, int vlan_id)
 Configure this stream to capture all packets with the matching VLAN ID. More...
 
int sc_stream_eth_shost (struct sc_stream *stream, const uint8_t *mac_addr)
 Configure this stream to capture all packets with the matching source MAC address. More...
 
int sc_stream_eth_type (struct sc_stream *stream, uint16_t eth_type)
 Configrue this stream to capture all packets with the matching ethernet type. More...
 
int sc_stream_ip_dest_host (struct sc_stream *stream, const char *dhost)
 Configure this stream to capture all packets with matching destination hostname. More...
 
int sc_stream_ip_dest_port (struct sc_stream *stream, const char *dport)
 Configure this stream to capture all packets with matching destination port. More...
 
int sc_stream_ip_source_host (struct sc_stream *stream, const char *shost)
 Configure this stream to capture all packets with matching source hostname. More...
 
int sc_stream_ip_source_port (struct sc_stream *stream, const char *sport)
 Configure this stream to capture all packets with matching source port. More...
 
int sc_stream_ip_protocol (struct sc_stream *stream, int protocol)
 Configure this stream to capture all packets with matching IP protocol. More...
 
int sc_thread_alloc (struct sc_thread **thread_out, const struct sc_attr *attr, struct sc_session *scs)
 Allocate a SolarCapture thread. More...
 
struct sc_session * sc_thread_get_session (const struct sc_thread *thread)
 Return the session associated with a thread.
 
void sc_thread_get_time (const struct sc_thread *thread, struct timespec *time_out)
 Return a thread's "current time". More...
 
void * sc_thread_calloc (struct sc_thread *thread, size_t bytes)
 Allocate memory to be used by a thread. More...
 
void * sc_thread_calloc_aligned (struct sc_thread *thread, size_t bytes, int align)
 Allocate memory to be used by a thread. More...
 
void sc_thread_mfree (struct sc_thread *thread, void *mem)
 Free memory. More...
 
int sc_thread_poll (struct sc_thread *thread)
 Poll a thread. More...
 
void sc_timer_expire_at (struct sc_callback *cb, const struct timespec *time)
 Request a callback at a given time. More...
 
void sc_timer_expire_after_ns (struct sc_callback *cb, int64_t delta_ns)
 Request a callback in the future. More...
 
void sc_timer_push_back_ns (struct sc_callback *cb, int64_t delta_ns)
 Push the expiry time further into the future. More...
 
int sc_timer_get_expiry_time (const struct sc_callback *cb, struct timespec *ts_out)
 Return the expiry time of a timer callback. More...
 
static uint64_t sc_ns_from_ts (const struct timespec *ts)
 Convert a timespec struct to nanoseconds. More...
 
static uint64_t sc_ns_from_tv (const struct timeval *tv)
 Convert a timeval struct to nanoseconds. More...
 
static uint64_t sc_ns_from_ms (uint64_t ms)
 Convert milliseconds to nanoseconds. More...
 
static uint64_t sc_ns_from_us (uint64_t us)
 Convert microseconds to nanoseconds. More...
 
int sc_vi_alloc (struct sc_vi **vi_out, const struct sc_attr *attr, struct sc_thread *thread, const char *interface)
 Allocate a VI instance. More...
 
int sc_vi_set_recv_node (struct sc_vi *vi, struct sc_node *node, const char *name_opt)
 Set the node a VI should deliver its received packets to. More...
 
int sc_vi_add_stream (struct sc_vi *vi, struct sc_stream *stream)
 Direct a packet stream to a VI. More...
 
struct sc_thread * sc_vi_get_thread (const struct sc_vi *vi)
 Return the thread associated with a VI. More...
 
const char * sc_vi_get_interface_name (const struct sc_vi *vi)
 Return the name of the network interface associated with a VI. More...
 
int sc_vi_group_alloc (struct sc_vi_group **vi_out, const struct sc_attr *attr, struct sc_session *session, const char *interface, int num_vis)
 Allocate a VI group. More...
 
struct sc_session * sc_vi_group_get_session (const struct sc_vi_group *vi_group)
 Return the session associated with a VI group. More...
 
int sc_vi_alloc_from_group (struct sc_vi **vi_out, const struct sc_attr *attr, struct sc_thread *thread, struct sc_vi_group *vi_group)
 Allocate a VI instance from a VI group. More...
 
int sc_vi_group_add_stream (struct sc_vi_group *vi_group, struct sc_stream *stream)
 Direct a packet stream to a group of VIs. More...
 

Detailed Description


Data Structure Documentation

struct sc_arg

Representation of an argument. Used by node init functions.

Data Fields
const char * name

Parameter name

enum sc_param_type type

Parameter type

union sc_arg val

Parameter value

union sc_arg.val
Data Fields
double dbl
int64_t i
struct sc_object * obj
const char * str
struct sc_dlist

Doubly linked list pointers.

Data Fields
struct sc_dlist * next

A pointer to next item in list (set to itself if it is at the end of the list).

struct sc_dlist * prev

A pointer to previous item in list (set to itself if it is at the start of the list).

struct sc_callback

A callback object.

Callback objects provide a way to be notified when an event of interest occurs.

Data Fields
sc_callback_handler_fn * cb_handler_fn

The callback to be called when the event of interest occurs.

struct sc_dlist cb_link
void * cb_private

Additional state to be passed to the callback function.

struct sc_node

Description of a node.

This is passed to every function used to call into the node.

Data Fields
char * nd_name

Name of the node, set automatically when creating node. nd_name is set to attribute name if this provided, otherwise sc_node_factory.nf_name with a unique node instance number appended

void * nd_private

Set by node for local state

const struct sc_node_type * nd_type

Type of node, set automatically on creation of the node

struct sc_node_link

Description of a link the node has.

This is passed to the node initialisation function

Data Fields
const char * name

Set when a link is added to the node

struct sc_node_factory

Struct to hold information about how to create an instance of this node.

Data Fields
sc_node_init_fn * nf_init_fn

The function to call to initialise the node

const char * nf_name

The name of the node.

int nf_node_api_ver

The version of solar_capture this node is designed for. The most recent version is stored in the macro SC_API_VER.

void * nf_private

For use as local state by the node sc_node_init_fn function only. This will not be passed to other node functions

void * nf_reserved[8]
const char * nf_source_file

The filename of the source file for this node. Use the FILE macro to set this.

struct sc_node_type

Describes a type of node.

This struct describes what functions are responsible for the behaviour of the node.

Data Fields
sc_node_add_link_fn * nt_add_link_fn

(Optional) Function to call when a node tries to establish a link from this node, set to NULL if not required.

sc_node_end_of_stream_fn * nt_end_of_stream_fn

(Optional) Function to call when nodes upstream indicate end of stream, set to NULL if not required.

const char * nt_name

Name of the node (set automatically by sc_node_type_alloc using sc_node_factory.nf_name.

sc_node_pkts_fn * nt_pkts_fn

Function to call when the node receives packets.

sc_node_prep_fn * nt_prep_fn

Function to call to prepare the node after the node graph is finalised.

void * nt_private

Additional state for the node.

sc_node_select_subnode_fn * nt_select_subnode_fn

(Optional) Function to call when another node tries to establish a link to this node, set to NULL if not required.

struct sc_packet

Representation of a packet.

This data-structure describes a packet. It includes pointers to the packet contents, meta-data relating to the packet and fields to support creating lists of packets.

Each sc_packet instance is usually associated with a buffer that holds the packet contents. A packet may span multiple such buffers, in which case the 'head' buffer uses frags and frags_tail to identify the remaining buffers (which are linked via the next field). Nodes should generally not use the frags, frags_n and frags_tail fields, because they are sometimes used in special ways. Instead nodes should use iov and iovlen to find the buffer(s) underlying an sc_packet.

Data Fields
uint16_t flags

flags defined below

struct sc_packet * frags

list of chained fragments

uint8_t frags_n

number of fragments in frags chain

struct sc_packet ** frags_tail

last fragment in chain

uint16_t frame_len

original frame length in bytes

struct iovec * iov

identifies packet data

uint8_t iovlen

number of entries in iov array

uintptr_t * metadata

packet metadata

struct sc_packet * next

next packet in a packet list

uint16_t reserved1
uint32_t reserved2
uint32_t ts_nsec

timestamp (nanoseconds)

uint64_t ts_sec

timestamp (seconds)

struct sc_packet_list

A list of packets or packet buffers.

Data Fields
struct sc_packet * head

Head of list

int num_frags

Number of pkt frags in the list

int num_pkts

Number of pkts in the list

struct sc_packet ** tail

Ptr to next field in tail of list

struct sc_iovec_ptr

An sc_iovec_ptr provides a convenient way to iterate over an iovec array without modifying it.

Data Fields
struct iovec io
const struct iovec * iov
int iovlen
struct sc_pkt_predicate

A packet predicate object.

Data Fields
void * pred_private
sc_pkt_predicate_test_fn * pred_test_fn
struct sc_session_error

A SolarCapture session error object returned by sc_session_error_get.

Data Fields
int err_errno
char * err_file
char * err_func
int err_line
char * err_msg
struct sc_attr

Attribute object.

Attributes are used to specify optional behaviours and parameters, usually when allocating other SolarCapture objects. Each attribute object defines a complete set of the attributes that SolarCapture understands.

For example, the "affinity_core" attribute controls which CPU core an sc_thread runs on.

The default values for attributes may be overridden by setting the environment variable SC_ATTR. For example:

SC_ATTR="log_level=3;snap=2"

Each function that takes an attribute argument will only be interested in a subset of the attributes specified by an sc_attr instance. Other attributes are ignored.

The set of attributes supported by SolarCapture may change between releases, so applications should where possible tolerate failures when setting attributes.

struct sc_object

An opaque object. Use this to pass all types of data that are not ints, doubles or char arrays (see SC_PARAM_INT, SC_PARAM_DBL and SC_PARAM_STR respectively for these) to nodes.

struct sc_vi

A VI object.

Macro Definition Documentation

#define SC_ARG_DBL (   _name,
  _val 
)    { .name = _name, .type = SC_PARAM_DBL, .val.dbl = _val }

Macro to construct a sc_arg struct of type SC_PARAM_DBL

Parameters
_nameName of argument.
_valValue of argument.
#define SC_ARG_INT (   _name,
  _val 
)    { .name = _name, .type = SC_PARAM_INT, .val.i = _val }

Macro to construct a sc_arg struct of type SC_PARAM_INT

Parameters
_nameName of argument.
_valValue of argument.
#define SC_ARG_OBJ (   _name,
  _val 
)    { .name = _name, .type = SC_PARAM_OBJ, .val.obj = _val }

Macro to construct a sc_arg struct of type SC_PARAM_OBJ

Parameters
_nameName of argument.
_valValue of argument.
#define SC_ARG_STR (   _name,
  _val 
)    { .name = _name, .type = SC_PARAM_STR, .val.str = _val }

Macro to construct a sc_arg struct of type SC_PARAM_STR

Parameters
_nameName of argument.
_valValue of argument.
#define SC_CONTAINER (   c_type,
  mbr_name,
  p_mbr 
)    ( (c_type*) ((char*)(p_mbr) - SC_MEMBER_OFFSET(c_type, mbr_name)) )

Fetch a pointer to the outer container of a given sc_dlist pointer.

Parameters
c_typeThe container type.
mbr_nameThe name of the field in the container holding the sc_dlist member.
p_mbrA pointer to the sc_dlist.
#define SC_DLIST_FOR_EACH_OBJ (   list,
  iter,
  mbr 
)
Value:
for( (iter) = SC_CONTAINER(typeof(*(iter)), mbr, (list)->next); \
&(iter)->mbr != (list); \
(iter) = SC_CONTAINER(typeof(*(iter)), mbr, (iter)->mbr.next) )
#define SC_CONTAINER(c_type, mbr_name, p_mbr)
Fetch a pointer to the outer container of a given sc_dlist pointer.
Definition: dlist.h:71

Create a for statement that loops over each container item in the list. It is not safe to modify the list using this macro, if list modifications are required see SC_DLIST_FOR_EACH_OBJ_SAFE.

Parameters
listA pointer to the head of the sc_dlist.
iterA pointer of the same type as the container.
mbrThe name of the field in the container containing the sc_dlist struct.
#define SC_DLIST_FOR_EACH_OBJ_SAFE (   list,
  iter,
  next_entry,
  mbr 
)
Value:
for( (iter) = SC_CONTAINER(typeof(*(iter)), mbr, (list)->next), \
(next_entry) = SC_CONTAINER(typeof(*(iter)), mbr, (iter)->mbr.next); \
&(iter)->mbr != (list); \
(iter) = (next_entry), \
(next_entry) = SC_CONTAINER(typeof(*(iter)), mbr, (iter)->mbr.next) )
#define SC_CONTAINER(c_type, mbr_name, p_mbr)
Fetch a pointer to the outer container of a given sc_dlist pointer.
Definition: dlist.h:71

Create a for statement that loops over each container item in the list which can be safely be modified during traversal.

Parameters
listA pointer to the head of the sc_dlist.
iterA pointer of the same type as the container.
next_entryA pointer of the same type as the container.
mbrThe name of the field in the container containing the sc_dlist struct.
#define SC_MEMBER_OFFSET (   c_type,
  mbr_name 
)    ((uint32_t) (uintptr_t)(&((c_type*)0)->mbr_name))

Calculate memory offset of a field within a struct.

Parameters
c_typeThe struct type.
mbr_nameThe field name to calculate the offset of.
#define SC_MEMBER_SIZE (   c_type,
  mbr_name 
)    (sizeof(((c_type*)0)->mbr_name))

Calculate the size of a field within a struct.

Parameters
c_typeThe struct type.
mbr_nameThe field to calculate the size of.
#define sc_node_fwd_error (   node,
  rc 
)    __sc_node_fwd_error((node), __FILE__, __LINE__, __func__, (rc))

Forward error from a failed sc call.

Parameters
nodeThe node that forwards the error
rcThe error code returned by the sc call

Call this function to propagate an error generated by SolarCapture.

#define sc_node_set_error (   node,
  errno_code,
  ... 
)
Value:
__sc_node_set_error((node), __FILE__, __LINE__, __func__, \
(errno_code), __VA_ARGS__)

Set error from within the implementation of a node.

Parameters
nodeThe node that originates the error
errno_codeAn error code from errno.h (or can be zero)

Call this function when returning an error to SolarCapture from a node. The value returned by this function should be passed on to the caller of the function reporting the error.

#define ST_CONSTANT (   name,
  val 
)    enum { name = val };a

A constant value in the template definition.

After the node has initialised its shared data structures name will be used as the field in the stats struct to update this data.

Parameters
nameThe field name.
valThe constant.
#define ST_FIELD (   type,
  name,
  kind 
)    type name;

A C basic type field in the template definition.

After the node has initialised its shared data structures name will be used as the field in the stats struct to update this data.

Parameters
typeThe basic data type.
nameThe field name.
kindA string to describe the kind of data. Examples used by SolarCapture nodes are pkt_count, ev_count, config, const, magnitude.
#define ST_FIELD_STR (   name,
  len,
  kind 
)    char name[len];

A string field in the template definition.

After the node has initialised its shared data structures name will be used as the field in the stats struct to update this data.

Parameters
nameThe field name.
lenThe length of the string.
kindA string to describe the kind of data. Examples used by SolarCapture nodes are pkt_count, ev_count, config, const, magnitude.
#define ST_STRUCT (   name)    struct name {

Start of the template definition.

After the node has initialised its shared data structures the resulting struct type for updating the stats will use name for its type.

Parameters
nameThe name of the template.

Typedef Documentation

typedef void( sc_callback_handler_fn)(struct sc_callback *, void *event_info)

A callback handler function.

Parameters
callbackThe callback struct registered with this callback.
event_infoIf callback was registered using sc_epoll_ctl this will contain the uint32_t epoll_events bitmask (see man 2 epoll_ctl) In all other cases this is not used.
typedef int( sc_node_add_link_fn)(struct sc_node *from_node, const char *link_name, struct sc_node *to_node, const char *to_name_opt)

Signature of nt_add_link_fn function.

Parameters
from_nodeThe node being linked from
link_nameThe name of the link
to_nodeThe node being linked to
to_name_optOptional name of ingress link

This method is optional and supports compound nodes. It is invoked on from_node when sc_node_add_link() is called, and gives the implementation an opportunity to select the subnode(s) to be linked from or issue an error if an attempt is made to create an unwanted link.

The implementation of this function should invoke sc_node_add_link() on from_node or on a subnode, or should return an error. If it returns an error it should do so by calling sc_node_set_error with a suitable error message, and return the value returned by sc_node_set_error.

The to_node and to_name_opt arguments should be passed unmodified. The implementation may invoke sc_node_add_link() multiple times to create links from multiple subnodes.

typedef void( sc_node_end_of_stream_fn)(struct sc_node *node)

Signature of nt_end_of_stream_fn function.

Parameters
nodeThe node.

This method is invoked when all incoming upstream nodes have indicated end-of-stream. After this method has been called sc_node_pkts_fn will not be called again. The implementation of this function may propagate end-of-stream through its outgoing links by calling sc_node_link_end_of_stream(). If this function is not provided end-of-stream will not propagate further through the node graph.

After the node has propagated end-of-stream to a node through its outgoing link it should not pass any more packets to this node.

This method is optional.

typedef int( sc_node_init_fn)(struct sc_node *node, const struct sc_attr *attr, const struct sc_node_factory *)

Signature of function to initialise a node.

Parameters
nodeThe node being initialised
factoryThe node factory
attrAttributes used to create the node. Valid only until this function exits.
argsParameters passed by user

This function is used to initialise an instance of a node. It will be called before the node graph has been finalised i.e. before all links between nodes have been established at the point when a python API user calls Thread.new_node() or when a C API user calls sc_node_alloc or sc_node_alloc_named. As much initialisation as possible should be done here, any initialisation that can't be done at this stage (for instance because it requires that the node graph is finalised) can be done later in sc_node_prep_fn.

attr will not remain valid once the init function returns. If you want to use attr after this function exits or use a modified version of attr you should use sc_attr_dup() to get a persistant writable version.

typedef void( sc_node_pkts_fn)(struct sc_node *node, struct sc_packet_list *packet_list)

Signature of nt_pkts_fn function.

Parameters
nodeThe node receiving the packets
packet_listList of packets

This function will be called when packets are received on any incoming link to the node. It is not possible to distinguish which incoming link the packets arrived from directly. If the node needs to distinguish between incoming streams then either upstream nodes must append metadata to the packets or the node must be constructed from subnodes with each subnode connected to a subset of incoming links.

Once this function is invoked the node gets ownership of the packets. Ownership is relinquished by invoking sc_forward_list or sc_forward to forward or free the packets.

typedef int( sc_node_prep_fn)(struct sc_node *node, const struct sc_node_link *const *links, int n_links)

Signature of nt_prep_fn function.

Parameters
nodeThe node being prepared
linksArray of outgoing links the node has
n_linksNumber of outgoing links in the array

This callback is invoked to prepare node for live packet processing. The implementation typically checks the egress links and saves them to private storage.

Any initialisation that could not be done in sc_node_init should be done here.

If the node needs to create subnodes and establish links it should be done before this stage in one of sc_node_init_fn, sc_node_select_subnode_fn or sc_node_add_link_fn.

Note that the array links is only valid for the duration of this function call, but the sc_node_link objects are valid for at least the lifetime of the node.

typedef struct sc_node*( sc_node_select_subnode_fn)(struct sc_node *node, const char *name, char **new_name_out)

Signature of nt_select_subnode_fn function.

Parameters
nodeThe node being linked to
nameThe name of the link (may be NULL)
new_name_outUse to set a different name for sub-node

This method is optional and supports compound nodes. It is invoked on node when sc_node_add_link() is called, and gives the implementation an opportunity to select an alternative subnode that should be linked to or issue an error if an attempt is made to create an unwanted link.

The implementation should return node or a subnode, or NULL to indicate that name is not valid for this node.

If a new name is specified via new_name_out then ownership is passed to the caller, and it will be freed with free().

Enumeration Type Documentation

The type of data the sc_object contains.

Enumerator
SC_OBJ_OPAQUE 

An opaque pointer

SC_OBJ_PKT_PREDICATE 

A packet predicate (see sc_pkt_predicate)

Possible parameter types that can be used for arguments in a node's init function.

Enumerator
SC_PARAM_STR 

const char pointer (nul terminated)

SC_PARAM_INT 

signed 64 bit int

SC_PARAM_OBJ 

sc_object pointer

SC_PARAM_DBL 

native double type

Function Documentation

int sc_attr_alloc ( struct sc_attr **  attr_out)

Allocate an attribute object.

Parameters
attr_outThe attribute object is returned here.

This function fails (returns -1) if the SC_ATTR environment variable is malformed. The SolarCapture error status is not set in this case because attribute objects are not associated with an sc_session.

int sc_attr_doc ( const char *  attr_name_opt,
const char ***  docs_out,
int *  docs_len_out 
)

Returns documentation for attributes. Used by solar_capture_doc.

Parameters
attr_name_optThe attribute name.
docs_outOn success, the resulting doc string output.
docs_len_outOn success, the length of the doc string output.
struct sc_attr* sc_attr_dup ( const struct sc_attr attr)

Duplicate an attribute object.

Parameters
attrThe attribute object.
Returns
A new attribute object.

This function is useful when you want to make non-destructive changes to an existing attribute object.

void sc_attr_free ( struct sc_attr attr)

Free an attribute object.

Parameters
attrThe attribute object.
void sc_attr_reset ( struct sc_attr attr)

Return attributes to their default values.

Parameters
attrThe attribute object.
int sc_attr_set_from_str ( struct sc_attr attr,
const char *  name,
const char *  val 
)

Set an attribute to a string value.

Parameters
attrThe attribute object.
nameName of the attribute.
valNew value for the attribute.

Returns an error if name is not a valid attribute name, or if it is not possible to convert val to a valid value for the attribute.

int sc_attr_set_int ( struct sc_attr attr,
const char *  name,
int64_t  val 
)

Set an attribute to an integer value.

Parameters
attrThe attribute object.
nameName of the attribute.
valNew value for the attribute.

Returns an error if name is not a valid attribute name, or if the attribute is not an integer attribute.

int sc_attr_set_str ( struct sc_attr attr,
const char *  name,
const char *  s 
)

Set an attribute to a string value.

Parameters
attrThe attribute object.
nameName of the attribute.
sNew value for the attribute (which can be NULL).

Returns an error if name is not a valid attribute name, or if the attribute is not a string attribute.

int sc_callback_alloc ( struct sc_callback **  cb_out,
const struct sc_attr attr,
struct sc_thread *  thread 
)

Allocate a callback object instance.

Parameters
cb_outThe allocated callback object is returned here
attrAttributes
threadThe thread the callback will be used with

This function allocates a callback object instance.

Before using the callback object the sc_callback::cb_handler_fn field must be initialised. The sc_callback::cb_private field may be used to store or point to caller-specific state.

A callback object can only be registered with a single event source at a time. If a callback object is registered with an event source it is "active". If an active callback is registered with an event source, it is automatically removed from the previous event source.

void sc_callback_free ( struct sc_callback cb)

Free a callback object instance.

Parameters
cbThe callback object to free

This function frees a callback object instance.

static int sc_callback_is_active ( const struct sc_callback cb)
inlinestatic

Returns true if a callback object is active.

Parameters
cbThe callback object
void sc_callback_on_idle ( struct sc_callback cb)

Request a callback when the thread is idle.

Parameters
cbThe callback object

The callback will be invoked from the associated thread's polling loop if there is no work done in that loop iteration. ie. The when thread is idle.

The callback is only invoked once. If further callbacks are wanted the callback must be reregistered explicitly.

static void sc_callback_remove ( struct sc_callback cb)
inlinestatic

Unregister a callback object from its event source.

Parameters
cbThe callback object

This function has no effect if the callback object is not active.

static void sc_dlist_init ( struct sc_dlist list)
inlinestatic

Initialise a pre-allocated sc_dlist to be an empty doubly linked list.

Parameters
listA pointer to the pre-allocated sc_dlist to be initialised.
static struct sc_dlist* sc_dlist_pop_head ( struct sc_dlist list)
static

Pop off the head of a list.

Parameters
listThe point to pop the head from.
static struct sc_dlist* sc_dlist_pop_tail ( struct sc_dlist list)
static

Pop the tail of a list.

Parameters
listThe point to pop the tail from.
static void sc_dlist_push_head ( struct sc_dlist list,
struct sc_dlist l 
)
inlinestatic

Prepend an item to the head of a doubly-linked list.

Parameters
listThe list to prepend to.
lThe item to prepend to list.
static void sc_dlist_push_tail ( struct sc_dlist list,
struct sc_dlist l 
)
inlinestatic

Append an item to the tail of a doubly-linked list.

Parameters
listThe list to append to.
lThe item to append to list.
static void sc_dlist_remove ( struct sc_dlist l)
inlinestatic

Remove an item from the list.

Parameters
lThe item to remove.
int sc_epoll_ctl ( struct sc_thread *  thread,
int  op,
int  fd,
unsigned  events,
struct sc_callback cb 
)

Request a callback when the thread is idle.

Parameters
threadThe thread managing fd
opEPOLL_CTL_ADD, EPOLL_CTL_MOD or EPOLL_CTL_DEL
fdThe file descriptor
eventsEvent flags (EPOLLIN, EPOLLOUT etc.)
cbThe callback object

Request a callback when a file descriptor is readable or writable, or if op is EPOLL_CTL_DEL then cancel a callback.

This function uses epoll as the underlying mechanism to manage file descriptors, so please refer to the documentation of epoll for detailed semantics.

events and cb are ignored when op is EPOLL_CTL_DEL.

A callback registered via this interface cannot be removed with sc_callback_remove, and must not be re-registered with another event source without first calling sc_epoll_ctl with op set to EPOLL_CTL_DEL.

void sc_forward ( struct sc_node node,
const struct sc_node_link link,
struct sc_packet packet 
)

Forward a single packet.

Parameters
nodeThe node's data structure
linkThe link to forward to
packetThe packet to forward
void sc_forward_list ( struct sc_node node,
const struct sc_node_link link,
struct sc_packet_list pl 
)

Forward a list of packets.

Parameters
nodeThe node's data structure
linkThe link to forward to
plThe list of packets to forward
static void sc_iovec_copy_from_end ( void *  dest_buf,
const struct iovec *  iov,
int  iovlen,
int  bytes 
)
inlinestatic

Copy data out of the end of a sc_iovec_ptr.

Parameters
dest_bufBuffer to copy to.
iovA pointer to an array of iovec objects.
iovlenThe number of iovec objects in iov. This must be > 0.
bytesNumber of bytes to copy.

Note: The caller must ensure that at least bytes of data are available in iov

static int sc_iovec_ptr_bytes ( const struct sc_iovec_ptr iovp)
inlinestatic

Returns the number of bytes represented by an sc_iovec_ptr.

Parameters
iovpThe sc_iovec_ptr
int sc_iovec_ptr_copy_out ( void *  dest,
struct sc_iovec_ptr iovp,
int  max_bytes 
)

Copy data out of an sc_iovec_ptr.

Parameters
destBuffer to copy to
iovpAn sc_iovec_ptr
max_bytesMax number of bytes to copy (length of dest)

Returns the number of bytes copied.

int sc_iovec_ptr_find_chr ( const struct sc_iovec_ptr iovp,
int  c 
)

Find offset of character in iovec.

Parameters
iovpAn sc_iovec_ptr
cCharacter to find

Returns the offset of first occurrence of character c in the memory reference by iovp, or -1 if not found.

static void sc_iovec_ptr_init ( struct sc_iovec_ptr iovp,
const struct iovec *  iov,
int  iovlen 
)
inlinestatic

Initialise a struct sc_iovec_ptr.

Parameters
iovpThe sc_iovec_ptr to initialise
iovPointer to array of 'struct iovec's
iovlenLength of the iov array
static void sc_iovec_ptr_init_buf ( struct sc_iovec_ptr iovp,
void *  buf,
int  len 
)
inlinestatic

Initialise a struct sc_iovec_ptr with a contiguous buffer.

Parameters
iovpThe sc_iovec_ptr to initialise
bufPointer to the start of the buffer
lenLength of the buffer
static void sc_iovec_ptr_init_packet ( struct sc_iovec_ptr iovp,
const struct sc_packet packet 
)
inlinestatic

Initialise a struct sc_iovec_ptr to point at packet data.

Parameters
iovpThe sc_iovec_ptr to initialise
packetThe packet
int sc_iovec_ptr_skip ( struct sc_iovec_ptr iovp,
int  bytes_to_skip 
)

Skip forward over an iovec.

Parameters
iovpAn sc_iovec_ptr
bytes_to_skipNumber of bytes to skip over

Returns the number of bytes skipped, which may be fewer than bytes_to_skip if the total amount of memory referenced by iovp is less.

static void sc_iovec_trim_end ( struct iovec *  iov,
uint8_t *  iovlen,
int  bytes 
)
inlinestatic

Remove data from the end of an iovec.

Parameters
iovA pointer to an array of iovec objects.
iovlenThe number of iovec objects in iov.
bytesThe number of bytes to trim.

Note: Caller must ensure that at least bytes of data are available in iov.

int sc_join_mcast_group ( struct sc_session *  scs,
const char *  interface,
const char *  group 
)

Join a multicast group.

Parameters
scsA session
interfaceThe network interface to join on
groupThe multicast group to join

This function joins multicast group group on interface interface. This is needed when you need to use the IGMP protocol to arrange that multicast packets are delivered to the adapter.

int sc_mailbox_alloc ( struct sc_mailbox **  mb_out,
const struct sc_attr attr,
struct sc_thread *  thread 
)

Allocate a mailbox.

Parameters
mb_outThe allocated mailbox is returned here.
attrAttributes (see sc_attr).
threadThe thread the mailbox will be in.

Mailboxes are used to pass packets between threads. To communicate you need a mailbox in each thread, and together they form a bi-directional link.

From SolarCapture 1.1 onwards it is not usually necessary to create mailboxes explicitly: They are created automatically when objects in different threads are connected together.

int sc_mailbox_connect ( struct sc_mailbox *  mb1,
struct sc_mailbox *  mb2 
)

Connect a pair of mailboxes.

Parameters
mb1The first mailbox.
mb2The second mailbox.

Link a pair of mailboxes so that they can communicate. A mailbox can only be connected once.

struct sc_node* sc_mailbox_get_send_node ( struct sc_mailbox *  mailbox)

Return a mailbox's "send node".

Parameters
mailboxThe mailbox.

This function returns the mailbox's send-node. Packets passed to this send-node are forwarded to the paired mailboxes recv-node.

int sc_mailbox_poll ( struct sc_mailbox *  mailbox,
struct sc_packet_list list 
)

Poll a mailbox.

Parameters
mailboxThe mailbox to poll.
listReceived packets are appended to this list.

This function should only be invoked on an unmanaged mailbox. It is necessary to poll a mailbox in order to receive packets from other threads, and to ensure that sent packets are delivered.

void sc_mailbox_send ( struct sc_mailbox *  mailbox,
struct sc_packet packet 
)

Send a packet through a mailbox to another thread.

Parameters
mailboxThe mailbox.
packetThe packet to send.

This function should only be invoked on an unmanaged mailbox.

Invoke this function to place a packet on a mailbox's send queue. NB. The packet may not actually be delivered to the remote thread until a later call to sc_mailbox_poll().

void sc_mailbox_send_list ( struct sc_mailbox *  mailbox,
struct sc_packet_list list 
)

Send a list of packets through a mailbox to another thread.

Parameters
mailboxThe mailbox.
listThe packets to send.

This function should only be invoked on an unmanaged mailbox.

Invoke this function to place packets on a mailbox's send queue. NB. The packets may not actually be delivered to the remote thread until a later call to sc_mailbox_poll().

int sc_mailbox_set_recv ( struct sc_mailbox *  mailbox,
struct sc_node node,
const char *  name_opt 
)

Connect a mailbox to a node.

Parameters
mailboxThe mailbox.
nodeThe node.
name_optOptional ingress port name (may be NULL).

Connect the output of a mailbox to a node. Packets passed to the send-node of the paired mailbox are passed to node.

void sc_node_add_info_int ( struct sc_node node,
const char *  field_name,
int64_t  field_val 
)

Export information to solar_capture_monitor.

Parameters
nodeThe node exporting state.
field_nameName of field.
field_valState to export.

Use this function to export static runtime information about a node to solar_capture_monitor. This function can be used in the implementation of a new node type, or in an application using a node.

See also sc_node_add_info_str() and sc_node_export_state().

void sc_node_add_info_str ( struct sc_node node,
const char *  field_name,
const char *  field_val 
)

Export information to solar_capture_monitor.

Parameters
nodeThe node exporting state.
field_nameName of field.
field_valState to export.

Use this function to export static runtime information about a node to solar_capture_monitor. This function can be used in the implementation of a new node type, or in an application using a node.

See also sc_node_add_info_int() and sc_node_export_state().

int sc_node_add_link ( struct sc_node from_node,
const char *  link_name,
struct sc_node to_node,
const char *  to_name_opt 
)

Add a link from one node to another.

Parameters
from_nodeNode to connect from.
link_nameName of the from_node's egress link.
to_nodeNode to connect to.
to_name_optOptional ingress port name (may be NULL).

Packets flow from node to node along links. This function adds a link from from_node to to_node.

link_name identifies from_node's egress link. By convention the default egress link is named "".

Some node types support multiple ingress ports so that the node can receive and separate multiple incoming packet streams. The name of the ingress port is given by to_name_opt.

Since SolarCapture 1.1, if the nodes are in different threads then this function automatically creates a link between the threads using mailboxes.

int sc_node_alloc ( struct sc_node **  node_out,
const struct sc_attr attr,
struct sc_thread *  thread,
const struct sc_node_factory factory,
const struct sc_arg args,
int  n_args 
)

Allocate a packet processing node.

Parameters
node_outThe allocated node is returned here
attrAttributes
threadThe thread the node will be in
factoryA node factory
argsAn array of arguments for node initialisation
n_argsThe number of arguments

Nodes perform packet processing services such as filtering, packet modification, import/export and packet injection.

A node factory allocates nodes of a particular type, and the argument list provides configuration for the node instance.

Use this function when you have a pointer to the node factory. For built-in nodes or nodes in a separate library it is simpler to use sc_node_alloc_named().

int sc_node_alloc_named ( struct sc_node **  node_out,
const struct sc_attr attr,
struct sc_thread *  thread,
const char *  factory_name,
const char *  lib_name,
const struct sc_arg args,
int  n_args 
)

Allocate a packet processing node by name.

Parameters
node_outThe allocated node is returned here.
attrAttributes.
threadThe thread the node will be in.
factory_nameName of the node factory.
lib_nameName of the node library (may be NULL).
argsAn array of arguments for node initialisation.
n_argsThe number of arguments.

Nodes perform packet processing services such as filtering, packet modification, import/export and packet injection.

This function allocates a node of type factory_name, and the argument list provides configuration for the node instance.

This function is a short-cut for sc_node_factory_lookup() followed by sc_node_alloc().

int sc_node_export_state ( struct sc_node node,
const char *  type_name,
int  type_size,
void *  pp_area 
)

Export dynamic state to solar_capture_monitor.

Parameters
nodeThe node exporting state
type_nameName of the exported datastructure
type_sizeSize in bytes of the exported datastructure
pp_areaPointer to memory is returned here

Use this function to export dynamic runtime information about a node to solar_capture_monitor. The information can include configuration information, statistics and/or other runtime state.

pp_area gives the address of a pointer that is overwritten with a pointer to the memory area large enough for an instance of type_name. So pp_area should be of type 'struct type_name**'.

The type type_name must already have been declared by creating the type_name_declare() function using declare_types.h::SC_DECLARE_TYPES and calling it.

See also sc_node_add_info_str() and sc_node_add_info_int(), which are useful for exporting static data.

int sc_node_factory_lookup ( const struct sc_node_factory **  factory_out,
struct sc_session *  session,
const char *  factory_name,
const char *  lib_name 
)

Find a node factory.

Parameters
factory_outThe node factory found.
sessionThe SolarCapture session.
factory_nameName of the node factory.
lib_nameName of the node library (may be NULL).

Finds the factory of name factory_name. It may be a built-in factory (in which case lib_name should be NULL) or a factory in an external library.

A factory library is a shared object file that contains one or more node factory instances.

lib_name may be NULL, in which case it defaults to being the same as the factory_name.

If lib_name contains a '/' character it is treated as the full path to the library object file.

Otherwise lib_name is the name of the library object file (either with or without a .so suffix). This function will search for the library object file in the following directories (in order):

  • the current working directory
  • directories specified by the SC_NODE_PATH environment variable
  • /usr/lib64/solar_capture/site-nodes
  • /usr/lib/x86_64-linux-gnu/solar_capture/site-nodes
  • /usr/lib64/solar_capture/nodes
  • /usr/lib/x86_64-linux-gnu/solar_capture/nodes

Depending on the target system, not all of the above directories may exist. In particular, the subdirectories of /usr/lib/x86_64-linux-gnu/ will only exist on Debian-derived systems using the multiarch structure for library folders. This is not expected to cause a problem at runtime.

If we decide to support 32-bit builds again, these directories will be searched instead (in order):

  • the current working directory
  • directories specified by the SC_NODE_PATH environment variable
  • /usr/lib/solar_capture/site-nodes
  • /usr/lib/i386-linux-gnu/solar_capture/site-nodes
  • /usr/lib/solar_capture/nodes
  • /usr/lib/i386-linux-gnu/solar_capture/nodes

If a library containing the named factory is not found by this search, the built-in nodes are searched last.

struct sc_thread* sc_node_get_thread ( const struct sc_node node)

Return the thread associated with a node.

Parameters
nodeThe node.
int sc_node_init_get_arg_dbl ( double *  v_out,
struct sc_node node,
const char *  name,
double  v_default 
)

Get a double argument.

Parameters
v_outOn success, the value is returned here
nodeThe node
nameThe name of the argument
v_defaultDefault returned if arg not found

This may only be called from sc_node_init_fn. Returns 0 if the argument is found, else 1 if not found (in which case v_default is copied to v_out), or -1 if the argument was found but is of the wrong type.

int sc_node_init_get_arg_int ( int *  v_out,
struct sc_node node,
const char *  name,
int  v_default 
)

Get an integer argument.

Parameters
v_outOn success, the value is returned here
nodeThe node
nameThe name of the argument
v_defaultDefault returned if arg not found

This may only be called from sc_node_init_fn. Returns 0 if the argument is found, else 1 if not found (in which case v_default is copied to v_out), or -1 if the argument was found but is of the wrong type.

int sc_node_init_get_arg_obj ( struct sc_object **  obj_out,
struct sc_node node,
const char *  name,
enum sc_object_type  obj_type 
)

Get an sc_object argument.

Parameters
obj_outOn success, the value is returned here
nodeThe node
nameThe name of the argument
obj_typeThe type of object wanted, or SC_OBJ_ANY

This may only be called from sc_node_init_fn. Returns 0 if the argument is found, else 1 if not found, or -1 if the argument was found but is of the wrong type (i.e. not an object, or the wrong type of object).

int sc_node_init_get_arg_str ( const char **  v_out,
struct sc_node node,
const char *  name,
const char *  v_default 
)

Get an string argument.

Parameters
v_outOn success, the value is returned here
nodeThe node
nameThe name of the argument
v_defaultDefault returned if arg not found

This may only be called from sc_node_init_fn. Returns 0 if the argument is found, else 1 if not found (in which case v_default is copied to v_out), or -1 if the argument was found but is of the wrong type.

The string returned is valid only until the sc_node_init_fn call returns.

void sc_node_link_end_of_stream ( struct sc_node node,
const struct sc_node_link link 
)

Indicate end-of-stream on a link.

Parameters
nodeThe node
linkThe link

It is a fatal error to forward any further packets through the link after calling this function.

int sc_node_prep_check_links ( struct sc_node node)

Check the node's links for any unused links.

Parameters
nodeThe node

This may only be called from sc_node_prep_fn(), and should only be used by nodes that find their links by calling sc_node_prep_get_link().

This function will complain about any links added to the node that have not been queried by sc_node_prep_get_link(). It may emit a warning, or generate an error.

Returns 0 if all is fine (or only warnings are needed). Returns -1 on error, which should be propagated out of sc_node_prep_fn().

const struct sc_node_link* sc_node_prep_get_link ( struct sc_node node,
const char *  link_name 
)

Find a named outgoing link.

Parameters
nodeThe node
link_nameName of the link

It returns NULL if the named link doesn't exist.

A node's sc_node_prep_fn can either use this mechanism to query its links, or it can simply iterate over the links passed as arguments to sc_node_prep_fn.

This function may only be called from sc_node_prep_fn.

See also sc_node_prep_check_links().

const struct sc_node_link* sc_node_prep_get_link_or_free ( struct sc_node node,
const char *  link_name 
)

Find a named outgoing link or return a link for freeing.

Parameters
nodeThe node
link_nameName of the link

This function behaves just like sc_node_prep_get_link(), except that if no link of that name has been added to the node, a special link is returned that frees packets.

link_name may be NULL, in which case a link for freeing packets is returned.

int sc_node_prep_get_pool ( struct sc_pool **  pool_out,
const struct sc_attr attr,
struct sc_node node,
const struct sc_node_link *const *  links,
int  n_links 
)

Get a packet pool that can be used to obtain empty packet buffers that can be passed to any of the given set of links.

Parameters
pool_outOn success, the pool is returned here
attrPacket pool attributes (optional, may be NULL)
nodeThe node
linksThe link(s) packets from the pool may be passed to (set to NULL for all)
n_linksNumber of links in 'links'

The node must only forward packets from the returned pool over the links identified by links and n_links. If n_links is 0 then it is assumed that packets from the pool may be forwarded over any of the node's links.

Restricting the links packets can be sent along allows SolarCapture to optimise the releasing of packets back to the pool when the node graph is finished with them.

This may only be called from sc_node_prep_fn.

int sc_node_type_alloc ( struct sc_node_type **  nt_out,
const struct sc_attr attr_opt,
const struct sc_node_factory factory 
)

Allocate an sc_node_type instance.

Parameters
nt_outThe allocated sc_node_type instance
attr_optOptional attributes (may be NULL)
factoryThe factory that created the node

At the time of writing attr_opt is not used and this call always succeeds. In future it may fail if the attributes are invalid in some way.

static uint64_t sc_ns_from_ms ( uint64_t  ms)
inlinestatic

Convert milliseconds to nanoseconds.

Parameters
msThe time in milliseconds to convert
Returns
Time in nanoseconds
static uint64_t sc_ns_from_ts ( const struct timespec *  ts)
inlinestatic

Convert a timespec struct to nanoseconds.

Parameters
tsThe timespec struct to convert
Returns
Time in nanoseconds
static uint64_t sc_ns_from_tv ( const struct timeval *  tv)
inlinestatic

Convert a timeval struct to nanoseconds.

Parameters
tvThe timeval struct to convert
Returns
Time in nanoseconds
static uint64_t sc_ns_from_us ( uint64_t  us)
inlinestatic

Convert microseconds to nanoseconds.

Parameters
usThe time in microseconds to convert
Returns
Time in nanoseconds
enum sc_object_type sc_object_type ( struct sc_object obj)

Return the type of data contained within the sc_object.

Parameters
objThe object to check the data type of.
int sc_opaque_alloc ( struct sc_object **  obj_out,
void *  opaque 
)

Allocate memory for an opaque sc_object.

Parameters
obj_outOn success the allocated object.
opaqueA pointer to the data to be wrapped by the object.
Returns
0 on success.
void sc_opaque_free ( struct sc_object obj)

Free an sc_object previously allocated using sc_opaque_alloc. Only use this to free an opaque sc_object. The underlying data wrapped by this object will not be freed.

Parameters
objThe object to free
void* sc_opaque_get_ptr ( const struct sc_object obj)

Get the opaque pointer stored in an sc_object.

Parameters
objThe object to fetch the opaque pointer from.
Returns
The opaque pointer.
void sc_opaque_set_ptr ( struct sc_object obj,
void *  opaque 
)

Set the opaque pointer in an sc_object.

Parameters
objThe object to set the pointer on
opaqueThe new opaque pointer to use
int sc_packet_append_iovec_ptr ( struct sc_packet packet,
struct sc_pool *  pool,
struct sc_iovec_ptr iovp,
int  snap 
)

Append data to a packet.

Parameters
packetThe packet to append data to
poolPacket pool to allocate frag buffers from (optional)
iovpIdentifies the data to copy in
snapThe maximum number of bytes to copy in

Returns 0 if all the requested data could be appended. Returns -1 if more space was needed and it was not possible to allocate fragment buffers. Returns -2 if the packet runs out of space (ie. the fragments chain would exceed the maximum chain length).

If you need to know the number of bytes appended, compare the packet frame_len before and after the call.

static int sc_packet_bytes ( struct sc_packet p)
inlinestatic

Return the size of the packet data in bytes.

Parameters
pA packet object.
static struct sc_packet* sc_packet_frags_tail ( struct sc_packet p)
static

Return a packet's last fragment.

Parameters
pA packet object.

The result is only valid if the packet has at least one fragment.

static void sc_packet_list_append ( struct sc_packet_list l,
struct sc_packet p 
)
inlinestatic

Append a packet to a list and finalise.

Parameters
lThe packet list.
pThe packet.
static void sc_packet_list_append_list ( struct sc_packet_list dest,
struct sc_packet_list src 
)
inlinestatic

Append a list to a list.

Parameters
destThe list to be extended.
srcThe list to be appended to dest.

After this call dest is finalised if and only if src was finalised.

src must be non-empty.

static void sc_packet_list_finalise ( struct sc_packet_list l)
inlinestatic

Finalise a list.

Parameters
lThe packet list.

If a list is not finalised, it is possible that the next pointer of tail is not NULL.

static void sc_packet_list_init ( struct sc_packet_list l)
inlinestatic

Initialise a list.

Parameters
lThe packet list.
static int sc_packet_list_is_empty ( const struct sc_packet_list l)
inlinestatic

Check if packet list is empty.

Parameters
lThe packet list.
static struct sc_packet* sc_packet_list_pop_head ( struct sc_packet_list pl)
static

Remove and return the head of the list.

Parameters
plThe packet list.

This must only be invoked on a non-empty list.

static void sc_packet_list_push_head ( struct sc_packet_list pl,
struct sc_packet p 
)
inlinestatic

Push a packet to the head of a list.

Parameters
plThe packet list.
pThe packet.
static struct sc_packet* sc_packet_list_tail ( struct sc_packet_list l)
static

Return the tail of current tail of the list.

Parameters
lThe packet list.
static void sc_packet_prefetch_r ( struct sc_packet p)
inlinestatic

Prefetch a packet for reading.

Parameters
pA packet object.
static void sc_packet_prefetch_rw ( struct sc_packet p)
inlinestatic

Prefetch a packet for reading and writing.

Parameters
pA packet object.
static struct timespec sc_packet_timespec ( const struct sc_packet p)
static

Return the timestamp of the packet in timespec format.

Parameters
pA packet object.
int sc_pkt_predicate_alloc ( struct sc_pkt_predicate **  pred_out,
int  private_bytes 
)

Allocate a packet predicate object.

Parameters
pred_outOn success the allocated sc_pkt_predicate object.
private_bytesSize of private memory area wanted.
Returns
0 on success.

Packet predicates are used to test packets against some criteria. The test function should return true (1) or false (0).

If private_bytes is non-zero then pred_private is initialised with a pointer to a region of memory of size private_bytes. The pred_private field may be used by the implementation to hold state.

struct sc_pkt_predicate* sc_pkt_predicate_from_object ( struct sc_object obj)

Convert a sc_object into a sc_pkt_predicate.

Parameters
objAn sc_object instance or NULL
Returns
NULL if obj is NULL otherwise the converted sc_pkt_predicate.
struct sc_object* sc_pkt_predicate_to_object ( struct sc_pkt_predicate pred)

Convert a sc_pkt_predicate into a sc_object.

Parameters
predAn sc_pkt_predicate instance or NULL
Returns
NULL if pred is NULL otherwise the converted sc_object.
struct sc_packet* sc_pool_duplicate_packet ( struct sc_pool *  pool,
struct sc_packet packet,
int  snap 
)

Duplicate a packet.

Parameters
poolThe pool to allocate buffers from
packetThe packet to duplicate
snapThe maximum number of bytes to copy
int sc_pool_get_packets ( struct sc_packet_list list,
struct sc_pool *  pool,
int  min_packets,
int  max_packets 
)

Get packet buffers from a pool.

Parameters
listList where retrieved packets are placed
poolThe packet pool
min_packetsMinimum number of buffers to be returned
max_packetsMaximum number of buffers to be returned

Returns the number of buffers added to list, or -1 if the minimum could not be satisfied.

list must be initialised on entry (and may already contain some packets), but need not be finalised. The list is finalised on return unless an error is returned (in which case the list is not modified).

Each packet returned is initialised as follows: pkt->flags = 0; pkt->frame_len = 0; pkt->iovlen = 1; pkt->iov[0] gives the base and extent of the DMA area The fragment list is empty

The following packet fields have undefined values: ts_sec, ts_nsec.

void sc_pool_on_threshold ( struct sc_pool *  pool,
struct sc_callback event,
int  threshold 
)

Request a callback when the pool is refilled.

Parameters
poolThe packet pool
eventThe event object
thresholdEvent fires when pool has >= threshold buffers

Registers an event handler that is invoked when the pool fill level reaches the specified threshold. If the pool fill level is already at or above the threshold, the handler will be invoked as soon as possible.

void sc_pool_return_packets ( struct sc_pool *  pool,
struct sc_packet_list list 
)

Return packets to a pool.

Parameters
poolThe packet pool
listList of packets to return

list must be initialised on entry, but can be empty. The packets on the list can have frags.

int sc_session_alloc ( struct sc_session **  scs_out,
const struct sc_attr attr 
)

Allocate a SolarCapture session.

Parameters
scs_outThe allocated session object is returned here
attrAttributes for the new session

This function allocates a SolarCapture session.

A session comprises a set of threads, VIs, nodes and/or other SolarCapture objects.

void sc_session_error_free ( struct sc_session *  scs,
struct sc_session_error err 
)

Frees an error object.

Parameters
scsThe session
errThe error

Frees a sc_session_error pointer returned by sc_session_error_get.

struct sc_session_error* sc_session_error_get ( struct sc_session *  scs)

Returns an error from a SolarCapture session.

Parameters
scsThe session

Returns a pointer to a sc_session_error struct representing the error encountered by session scs. The caller should pass the pointer to sc_session_error_free once once done with it.

If no error has occurred, this function returns NULL.

int sc_session_go ( struct sc_session *  scs)

Start a SolarCapture session.

Parameters
scsThe session

Prepare the session scs (if necessary) and start the managed threads. This is usually called just once, after allocating resources. It can also be called after sc_session_pause() to restart a paused session.

int sc_session_pause ( struct sc_session *  scs)

Pause a SolarCapture session.

Parameters
scsThe session

Pause the threads managed by session scs.

int sc_session_prepare ( struct sc_session *  scs)

Prepare a SolarCapture session.

Parameters
scsThe session

Prepare the session scs. This step includes finalising resource allocations, preparing nodes, and starting packet capture. Managed threads are started in the "paused" state.

Note that although packet capture is started, you may get packet loss if the threads managing 'sc_vi's are not started soon afterwards.

Call sc_session_go() to start the managed threads and begin packet processing.

int sc_stream_all ( struct sc_stream *  stream)

Configure this stream to capture all packets that haven't been caught by another stream.

Parameters
streamThe stream to send the packets to.

Returns 0 on success, a negative number on failure.

int sc_stream_alloc ( struct sc_stream **  stream_out,
const struct sc_attr attr,
struct sc_session *  scs 
)

Create a new stream object for this session.

Parameters
stream_outOn success, the created stream.
attrAttributes to pass in.
scsThe session this stream is for.

This function returns 0 on success or a negative number on failure.

int sc_stream_eth_dhost ( struct sc_stream *  stream,
const uint8_t *  mac_addr 
)

Configure this stream to capture all packets with the matching destination MAC address.

Parameters
streamThe stream to send the packets to.
mac_addrThe destination MAC address to match against.

Returns 0 on success, a negative number on failure.

int sc_stream_eth_shost ( struct sc_stream *  stream,
const uint8_t *  mac_addr 
)

Configure this stream to capture all packets with the matching source MAC address.

Parameters
streamThe stream to send the packets to.
mac_addrThe source MAC address to match against.

Returns 0 on success, a negative number on failure.

int sc_stream_eth_type ( struct sc_stream *  stream,
uint16_t  eth_type 
)

Configrue this stream to capture all packets with the matching ethernet type.

Parameters
streamThe stream to send the packets to.
eth_typeThe internet layer protocol to match against.

Returns 0 on success, a negative number on failure.

int sc_stream_eth_vlan_id ( struct sc_stream *  stream,
int  vlan_id 
)

Configure this stream to capture all packets with the matching VLAN ID.

Parameters
streamThe stream to send the packets to.
vlan_idThe VLAN ID to match against.

Returns 0 on success, a negative number on failure.

int sc_stream_free ( struct sc_stream *  stream)

Free a previously created stream.

Parameters
streamThe stream to free.

This function will always return 0.

int sc_stream_ip_dest_host ( struct sc_stream *  stream,
const char *  dhost 
)

Configure this stream to capture all packets with matching destination hostname.

Parameters
streamThe stream to send the packets to.
dhostThe destination hostname to match against.

Returns 0 on success, a negative number on failure.

int sc_stream_ip_dest_hostport ( struct sc_stream *  stream,
int  protocol,
const char *  dhost,
const char *  dport 
)

Configure this stream to capture all packets with the matching protocol, destination hostname and destination port.

Parameters
streamThe stream to send the packets to.
protocolThe transport layer protocol to match against.
dhostThe destination hostname to match against.
dportThe destination port to match against.

Returns 0 on success, a negative number on failure.

int sc_stream_ip_dest_port ( struct sc_stream *  stream,
const char *  dport 
)

Configure this stream to capture all packets with matching destination port.

Parameters
streamThe stream to send the packets to.
dportThe destination port to match against.

Returns 0 on success, a negative number on failure.

int sc_stream_ip_protocol ( struct sc_stream *  stream,
int  protocol 
)

Configure this stream to capture all packets with matching IP protocol.

Parameters
streamThe stream to send the packets to.
protocolThe IP protocol to match against.

Returns 0 on success, a negative number on failure.

int sc_stream_ip_source_host ( struct sc_stream *  stream,
const char *  shost 
)

Configure this stream to capture all packets with matching source hostname.

Parameters
streamThe stream to send the packets to.
shostThe source hostname to match against.

Returns 0 on success, a negative number on failure.

int sc_stream_ip_source_hostport ( struct sc_stream *  stream,
const char *  shost,
const char *  sport 
)

Configure this stream to capture all packets with the matching protocol, source hostname and source port.

Parameters
streamThe stream to send the packets to.
shostThe source hostname to match against.
sportThe source port to match against.

Returns 0 on success, a negative number on failure.

int sc_stream_ip_source_port ( struct sc_stream *  stream,
const char *  sport 
)

Configure this stream to capture all packets with matching source port.

Parameters
streamThe stream to send the packets to.
sportThe source port to match against.

Returns 0 on success, a negative number on failure.

int sc_stream_mismatch ( struct sc_stream *  stream)

Configure this stream to capture all packets that haven't been caught by another stream and are not requested by the kernel network stack.

Parameters
streamThe stream to send the packets to.

Returns 0 on success, a negative number on failure.

int sc_stream_reset ( struct sc_stream *  stream)

Remove all stream filters.

Parameters
streamThe stream to remove the filters from.
int sc_stream_set_str ( struct sc_stream *  stream,
const char *  str 
)

Configure the stream to capture all packets matching the specified filter string. This is the preferred way of adding filters to a stream.

Parameters
streamThe stream to send the packets to.
strThe filter to match against. Filters are constructed as a comma separated list of key-value pairs, except for the special cases "all", "mismatch", "ip", "tcp", and "udp". Available keywords are:
key-value pair Description
dmac=xx:xx:xx:xx:xx:xx Filter on destination MAC address.
smac=xx:xx:xx:xx:xx:xx Filter on source MAC addres.
vid=INT Filter on VLAN id number.
eth_type=ip|INT Filter on the ethernet type number (see net/ethertype.h header).
shost=hostname Filter on source hostname, hostname can be either an IP address or a resolvable string.
dhost=hostname Filter on destination hostname, hostname can be either an IP address or a resolvable string.
ip_protocol=udp|tcp|INT Filter on ip protocol (set netinet/in.h header).
sport=INT Filter on source port.
dport=INT Filter on destination port.
all All packets to this stream that haven't been filtered by another stream.
mismatch All packets to this stream that haven't been filtered by another stream and are not requested by the kernel network stack.
ip Shorthand for eth_type=ip.
tcp Shorthand for ip_protocol=tcp.
udp Shorthand for ip_protocol=udp.

This function will return 0 on success or a negative number on failure.

int sc_thread_alloc ( struct sc_thread **  thread_out,
const struct sc_attr attr,
struct sc_session *  scs 
)

Allocate a SolarCapture thread.

Parameters
thread_outThe allocated thread object is returned here
attrAttributes
scsThe session

This function allocates a SolarCapture thread.

Normally SolarCapture creates an OS thread for the sc_thread object, and starts the thread when sc_session_go() is called. If the 'managed' attribute is set to false, then it is up to the application to create an underlying thread.

void* sc_thread_calloc ( struct sc_thread *  thread,
size_t  bytes 
)

Allocate memory to be used by a thread.

Parameters
threadThe thread
bytesSize of memory area to allocate

This function is intended to be used for allocating small amounts of memory that are used on performance critical paths, such as the private state used by the implementation of a node.

The memory region may overlap cache lines used by other allocations from this API for the same thread.

void* sc_thread_calloc_aligned ( struct sc_thread *  thread,
size_t  bytes,
int  align 
)

Allocate memory to be used by a thread.

Parameters
threadThe thread
bytesSize of memory area wanted
alignAlignment of memory area wanted

This function is intended to be used for allocating small amounts of memory that are used on performance critical paths, such as the private state used by the implementation of a node.

The memory region may overlap cache lines used by other allocations from this API for the same thread.

void sc_thread_get_time ( const struct sc_thread *  thread,
struct timespec *  time_out 
)

Return a thread's "current time".

Parameters
threadThe thread
time_outThe current time is returned here

Each thread's current time is updated by the polling loop, so may or may not be up-to-date when you call this function. The clock used as the time base is CLOCK_REALTIME.

void sc_thread_mfree ( struct sc_thread *  thread,
void *  mem 
)

Free memory.

Parameters
threadThe thread
memThe memory area

Use this function to free memory allocated with sc_thread_calloc or sc_thread_calloc_aligned.

int sc_thread_poll ( struct sc_thread *  thread)

Poll a thread.

Parameters
threadThe thread.

Use this function to poll an unmanaged thread. This drives events through the node graph.

Note: For managed threads this functionality is provided internally by solar_capture.

The return value indicates whether any work was done. If the return is true, then one of the following has happened: Packets have been received by a VI; Packets have been received by a mailbox; Packets have been handled by a node; A timer has expired.

void sc_timer_expire_after_ns ( struct sc_callback cb,
int64_t  delta_ns 
)

Request a callback in the future.

Parameters
cbA callback object
delta_nsHow far in the future in nanoseconds.

The callback will be invoked at or after the specified time delta in nanoseconds. If delta_ns is zero or negative then the handler function will be invoked as soon as possible.

void sc_timer_expire_at ( struct sc_callback cb,
const struct timespec *  time 
)

Request a callback at a given time.

Parameters
cbA callback object
timeTime at which callback is requested

The callback cb will be invoked at or after the specified time. If the time is in the past, then the handler function will be invoked as soon as possible.

The time is relative to the system realtime clock (CLOCK_REALTIME), which is the same clock returned by sc_thread_get_time().

int sc_timer_get_expiry_time ( const struct sc_callback cb,
struct timespec *  ts_out 
)

Return the expiry time of a timer callback.

Parameters
cbA callback object
ts_outThe expiry time is returned here
Returns
Zero if cb is a timer else -1
void sc_timer_push_back_ns ( struct sc_callback cb,
int64_t  delta_ns 
)

Push the expiry time further into the future.

Parameters
cbA callback object
delta_nsHow far in the future in nanoseconds.

This function pushes the expiry time of a timer callback further into the future.

The callback cb must either be a currently active timer registered with sc_timer_expire_at() or sc_timer_expire_after_ns(), or it must be an inactive timer. ie. The most recent use of cb must have been as a timer callback.

If cb is active, then it is rescheduled at its current expiry time plus delta_ns. If it is not active then it is scheduled at its previous expiry time plus delta_ns.

int sc_vi_add_stream ( struct sc_vi vi,
struct sc_stream *  stream 
)

Direct a packet stream to a VI.

Parameters
viThe VI receiving packets
streamThe packet stream

Arrange for the packet stream identified by stream to be copied or steered to vi.

int sc_vi_alloc ( struct sc_vi **  vi_out,
const struct sc_attr attr,
struct sc_thread *  thread,
const char *  interface 
)

Allocate a VI instance.

Parameters
vi_outThe allocated VI is returned here
attrAttributes
threadThe thread the VI will be in
interfaceThe network interface to receive packets from

A VI is a "virtual network interface" and supports receiving packets from the network. Packets received by a VI are passed to nodes (sc_node) for processing.

int sc_vi_alloc_from_group ( struct sc_vi **  vi_out,
const struct sc_attr attr,
struct sc_thread *  thread,
struct sc_vi_group *  vi_group 
)

Allocate a VI instance from a VI group.

Parameters
vi_outThe allocated VI is returned here
attrAttributes
threadThe thread the VI will be in
vi_groupThe VI group

See also sc_vi_group_alloc() and sc_vi_alloc().

const char* sc_vi_get_interface_name ( const struct sc_vi vi)

Return the name of the network interface associated with a VI.

Parameters
viThe VI

This call returns the name of the network interface associated with the sc_vi object. This can be different from the interface name used to create the sc_vi when application clustering is used.

The network interface name is most often needed so that the application can create an injector on the same interface as a VI.

struct sc_thread* sc_vi_get_thread ( const struct sc_vi vi)

Return the thread associated with a VI.

Parameters
viThe VI
int sc_vi_group_add_stream ( struct sc_vi_group *  vi_group,
struct sc_stream *  stream 
)

Direct a packet stream to a group of VIs.

Parameters
vi_groupThe VI group receiving packets
streamThe packet stream

Arrange for the packet stream identified by stream to be copied or steered to the VIs that comprise vi_group.

Note that packets are spread over the VIs in a group by computing a hash on the addresses in the packet headers. Normally the hash is computed over the IP addresses, and for TCP packets also the port numbers. The hash selects a VI within the group, so that packets with the same addresses are consistently delivered to the same VI.

If stream identifies a set of packets that all have the same source and destination IP addresses (and ports in the case of TCP) then they will all be received by a single VI.

int sc_vi_group_alloc ( struct sc_vi_group **  vi_out,
const struct sc_attr attr,
struct sc_session *  session,
const char *  interface,
int  num_vis 
)

Allocate a VI group.

Parameters
vi_outThe allocated VI is returned here
attrAttributes
sessionThe SolarCapture session
interfaceThe network interface to receive packets from
num_visThe number of VIs in the group

A VI group provides a way to distribute packet capture over multiple threads. A VI group consists of a set of VIs, each of which receives a distinct subset of the streams directed at the group.

Streams are directed to a group by calling sc_vi_group_add_stream().

While a VI allocated from a group receives packets from streams directed to the group (sc_vi_group_add_stream()), it is also possible to use sc_vi_add_stream() to direct a specific stream to a specific member of the group.

struct sc_session* sc_vi_group_get_session ( const struct sc_vi_group *  vi_group)

Return the session associated with a VI group.

Parameters
vi_groupThe VI group
int sc_vi_set_recv_node ( struct sc_vi vi,
struct sc_node node,
const char *  name_opt 
)

Set the node a VI should deliver its received packets to.

Parameters
viThe VI receiving packets
nodeThe node to deliver packets to
name_optOptional ingress port name (may be NULL)

Since SolarCapture 1.1, if node is in a different thread from vi, then this function automatically creates a link between the threads using mailboxes.