- interface packet interception capability added
This commit is contained in:
parent
96bc37f271
commit
7af522335d
@ -68,6 +68,8 @@ EthInterface *ethintf_new(EthIODef *io) {
|
|||||||
|
|
||||||
memset(ðIntf->evtCbTable, 0, sizeof(EthIntfEventCbTable));
|
memset(ðIntf->evtCbTable, 0, sizeof(EthIntfEventCbTable));
|
||||||
|
|
||||||
|
ethIntf->interceptCb = NULL;
|
||||||
|
|
||||||
ethIntf->linkState = false;
|
ethIntf->linkState = false;
|
||||||
|
|
||||||
ethintf_register(ethIntf);
|
ethintf_register(ethIntf);
|
||||||
@ -88,8 +90,16 @@ static ThreadReturnType task_ethintf(ThreadParamType param) {
|
|||||||
case ETH_IIE_RECV_NOTIFY: {
|
case ETH_IIE_RECV_NOTIFY: {
|
||||||
intf->ioDef->llRxRead(intf->ioDef); // read packets, will invoke RxStore
|
intf->ioDef->llRxRead(intf->ioDef); // read packets, will invoke RxStore
|
||||||
while (mq_avail(intf->rxQ) > 0) {
|
while (mq_avail(intf->rxQ) > 0) {
|
||||||
|
// get the raw packet
|
||||||
RawPckt rawPckt = mq_top(intf->rxQ);
|
RawPckt rawPckt = mq_top(intf->rxQ);
|
||||||
mq_pop(intf->rxQ);
|
mq_pop(intf->rxQ);
|
||||||
|
|
||||||
|
// packet interception, if defined
|
||||||
|
if (intf->interceptCb != NULL) {
|
||||||
|
intf->interceptCb(intf, &rawPckt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// packet processing
|
||||||
packsieve_input(&intf->sieve, &rawPckt);
|
packsieve_input(&intf->sieve, &rawPckt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +133,7 @@ void ethinf_receive(EthInterface *intf, const RawPckt *rawPckt) {
|
|||||||
bool pushOK = mq_push(intf->rxQ, rawPckt);
|
bool pushOK = mq_push(intf->rxQ, rawPckt);
|
||||||
if (!pushOK) {
|
if (!pushOK) {
|
||||||
dynmem_free(rawPckt->payload);
|
dynmem_free(rawPckt->payload);
|
||||||
ERROR("Input queue full, packet dropped!\n");
|
ERROR("Interface RECEIVE queue full, packet dropped!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +141,7 @@ void ethinf_transmit(EthInterface *intf, const RawPckt *rawPckt) {
|
|||||||
if (mq_push(intf->txQ, rawPckt)) { // push packet onto the message queue
|
if (mq_push(intf->txQ, rawPckt)) { // push packet onto the message queue
|
||||||
ethinf_push_notification(intf, ETH_IIE_TRANSMIT_NOTIFY, 0); // notify processing thread of the peding transmit
|
ethinf_push_notification(intf, ETH_IIE_TRANSMIT_NOTIFY, 0); // notify processing thread of the peding transmit
|
||||||
} else {
|
} else {
|
||||||
ERROR("Interface transmit queue full!\n");
|
ERROR("Interface TRANSMIT queue full, packet dropped!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,3 +200,7 @@ void ethinf_up(EthInterface *intf) {
|
|||||||
void ethinf_down(EthInterface *intf) {
|
void ethinf_down(EthInterface *intf) {
|
||||||
intf->up = false;
|
intf->up = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ethinf_set_intercept_callback(EthInterface * intf, EthIntfInterceptCb cb) {
|
||||||
|
intf->interceptCb = cb;
|
||||||
|
}
|
@ -3,15 +3,15 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "packet_sieve.h"
|
|
||||||
#include "prefab/packet_parsers/packet_parsers.h"
|
|
||||||
#include "prefab/packet_parsers/ipv4_types.h"
|
|
||||||
#include "arp_cache.h"
|
#include "arp_cache.h"
|
||||||
#include "connection_block.h"
|
#include "connection_block.h"
|
||||||
#include "msg_queue.h"
|
|
||||||
#include "gen_queue.h"
|
#include "gen_queue.h"
|
||||||
|
#include "msg_queue.h"
|
||||||
|
#include "packet_sieve.h"
|
||||||
#include "prefab/conn_blocks/ipv4/ip_assembler.h"
|
#include "prefab/conn_blocks/ipv4/ip_assembler.h"
|
||||||
#include "prefab/packet_parsers/dhcp.h"
|
#include "prefab/packet_parsers/dhcp.h"
|
||||||
|
#include "prefab/packet_parsers/ipv4_types.h"
|
||||||
|
#include "prefab/packet_parsers/packet_parsers.h"
|
||||||
|
|
||||||
#include <etherlib_options.h>
|
#include <etherlib_options.h>
|
||||||
|
|
||||||
@ -47,6 +47,13 @@ struct EthInterface_;
|
|||||||
|
|
||||||
typedef void (*EthIntfEvtCb)(struct EthInterface_ *intf);
|
typedef void (*EthIntfEvtCb)(struct EthInterface_ *intf);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function prototype for intercepting packets on an interface.
|
||||||
|
* @param intf pointer to corresponding Ethernet interface
|
||||||
|
* @param rawPckt pointer to the IMMUTABLE raw packet
|
||||||
|
*/
|
||||||
|
typedef void (*EthIntfInterceptCb)(struct EthInterface_ *intf, const RawPckt *rawPckt);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ETH_EVT_LINK_CHANGE = 0,
|
ETH_EVT_LINK_CHANGE = 0,
|
||||||
ETH_EVT_IP_CHANGE = 1,
|
ETH_EVT_IP_CHANGE = 1,
|
||||||
@ -83,6 +90,8 @@ typedef struct EthInterface_ {
|
|||||||
EthIntfEventCbTable evtCbTable; ///< Event callback table
|
EthIntfEventCbTable evtCbTable; ///< Event callback table
|
||||||
bool linkState; ///< Interface link state
|
bool linkState; ///< Interface link state
|
||||||
bool up; ///< Is the interface up?
|
bool up; ///< Is the interface up?
|
||||||
|
EthIntfInterceptCb interceptCb; ///< Intercept callback
|
||||||
|
|
||||||
} EthInterface;
|
} EthInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -152,6 +161,7 @@ void ethinf_set_link_state(EthInterface * intf, bool ls);
|
|||||||
/**
|
/**
|
||||||
* Get link state.
|
* Get link state.
|
||||||
* @param intf pointer to Ethernet interface
|
* @param intf pointer to Ethernet interface
|
||||||
|
* @return link state
|
||||||
*/
|
*/
|
||||||
bool ethinf_get_link_state(EthInterface *intf);
|
bool ethinf_get_link_state(EthInterface *intf);
|
||||||
|
|
||||||
@ -167,4 +177,11 @@ void ethinf_up(EthInterface *intf);
|
|||||||
*/
|
*/
|
||||||
void ethinf_down(EthInterface *intf);
|
void ethinf_down(EthInterface *intf);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set callback for packet interception.
|
||||||
|
* @param intf pointer to Ethernet interface
|
||||||
|
* @param cb intercept callback pointer
|
||||||
|
*/
|
||||||
|
void ethinf_set_intercept_callback(EthInterface *intf, EthIntfInterceptCb cb);
|
||||||
|
|
||||||
#endif // ETHERLIB_ETH_INTERFACE_H
|
#endif // ETHERLIB_ETH_INTERFACE_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user