The plugin version also illustrates working with data-plane redundancy.
All the code to implement the plugin version is in the file sandbox/src/lib/passthru-plugin/passthru_main.c
.
For a general introduction to plugins, see Plugin Architecture, Plugin Functionality and Service Chaining, and Writing a Plugin. For a somewhat more complex example than this one, see The Sync Equilibrium Application Using Plugins.
passthru_entry()
) is called by the management daemon when it loads the plugin as a dynamic object. The control event handler (in this example, passthru_ctrl_hdlr()
)is called by the plugin when the service receives an initialization or configuration data-received event. The data event handler (in this example, passthru_data_hdlr()
) is called by the plugin when the service receives an event related to packets.
The plugin entry function is specified in the XML configuration file, which the example provides at sandbox/src/etc/passthru-plugin.xml.
After installation, the system places this file in /opt/sdk/pkg/package-name.xml
on the MultiServices PIC.
This plugin example illustrates your ability to choose whether to use the session functionality and whether to store configuration information in the policy database. Using the policy database with the session framework allows you to apply stored decisions to forward and reverse packet flows without repeated lookups; your code just handles the data events.
To illustrate this flexibility, processing and configuration #defines are established at the beginning of the file. This version enables the processing mode SESSION_BASED_MODE
, which allows full session affinity and session context. In this mode, the plugin will receive separate data events for the first packet and other packets, as well as session open, close, and destroy notifications.
msvcs_plugin_params_t
, and calls msvcs_plugin_register(¶ms)
.MSVCS_CONTROL_EV_INIT
event. This is where your code stores the configuration in the policy database.
This handler also includes code to process data plane redundancy states, accessible through the MSVCS_CONTROL_EV_HA_INFO_BLOB
event. For an introduction to this functionality, see Data-Plane Redundancy.
MSVCS_DATA_EV_SM_INIT
event. Additional object cache memory is allocated on MSVCS_DATA_EV_FIRST_PKT_PROC
, to store the session context.
The code handles the MSVCS_DATA_FIRST_PKT_PROC
event to get session information from the first packet. Once this information has been saved, it is then available to all other packets in the flow.
The code uses the MSVCS_DATA_EV_PKT_PROC
event to retrieve the stored session information and apply it to the forward and reverse packet flows using framework APIs:
// find the string stored in the session context describing what we want: if(md_ctx->sc_flags & MSVCS_CTX_FLAGS_DIR_FORWARD) { msvcs_session_get_ext_handle((msvcs_session_t *)md_ctx->sc_session, (uint8_t)plugin_id, (void **)&desc, NULL); } else if(md_ctx->sc_flags & MSVCS_CTX_FLAGS_DIR_REVERSE) { msvcs_session_get_ext_handle((msvcs_session_t *)md_ctx->sc_session, (uint8_t)plugin_id, NULL, (void **)&desc); } else { // should never happen DLOG(LOG_ALERT, "%s: Direction of packet is not defined."); } ... return MSVCS_ST_PKT_FORWARD;
The code also handles the other basic data events.
Notice that the plugin uses jbuf APIs only to find the IP header and discover the protocol. You still use the pullup_bytes()
function to get contiguous data, but you no longer need to perform complex manipulations of the data in the jbuf.