- 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>
|
||||||
|
|
||||||
@ -19,14 +19,14 @@
|
|||||||
* Ethernet interface low level definition.
|
* Ethernet interface low level definition.
|
||||||
*/
|
*/
|
||||||
typedef struct EthIODef_ {
|
typedef struct EthIODef_ {
|
||||||
int (*llTxTrigger)(struct EthIODef_ * io, MsgQueue * mq); ///< Function pointer to low-level transmit function trigger
|
int (*llTxTrigger)(struct EthIODef_ *io, MsgQueue *mq); ///< Function pointer to low-level transmit function trigger
|
||||||
int (*llTxDone)(struct EthIODef_ * io, const RawPckt * rawPckt); ///< Transmission done (interrupt) callback
|
int (*llTxDone)(struct EthIODef_ *io, const RawPckt *rawPckt); ///< Transmission done (interrupt) callback
|
||||||
int (*llLinkChg)(struct EthIODef_ * io, int linkState); ///< Link change interrupt
|
int (*llLinkChg)(struct EthIODef_ *io, int linkState); ///< Link change interrupt
|
||||||
int (*llRxStore)(struct EthIODef_ * io, const RawPckt * rawPckt); ///< Receive done callback
|
int (*llRxStore)(struct EthIODef_ *io, const RawPckt *rawPckt); ///< Receive done callback
|
||||||
int (*llError)(struct EthIODef_ * io, int error); ///< Low-level error interrupt
|
int (*llError)(struct EthIODef_ *io, int error); ///< Low-level error interrupt
|
||||||
int (*llRxRead)(struct EthIODef_ * io); ///< Read received packets
|
int (*llRxRead)(struct EthIODef_ *io); ///< Read received packets
|
||||||
int (*llRxNotify)(struct EthIODef_ * io); ///< Notify of received packets
|
int (*llRxNotify)(struct EthIODef_ *io); ///< Notify of received packets
|
||||||
void * tag; ///< Some arbitrary tagging
|
void *tag; ///< Some arbitrary tagging
|
||||||
|
|
||||||
} EthIODef;
|
} EthIODef;
|
||||||
|
|
||||||
@ -45,7 +45,14 @@ typedef enum {
|
|||||||
|
|
||||||
struct EthInterface_;
|
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,
|
||||||
@ -58,31 +65,33 @@ typedef enum {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
EthIntfEvtCb linkChange; ///< Link change event
|
EthIntfEvtCb linkChange; ///< Link change event
|
||||||
EthIntfEvtCb ipChange; ///< IP-address changed
|
EthIntfEvtCb ipChange; ///< IP-address changed
|
||||||
} EthIntfEventCbTable;
|
} EthIntfEventCbTable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ethernet interface representation.
|
* Ethernet interface representation.
|
||||||
*/
|
*/
|
||||||
typedef struct EthInterface_ {
|
typedef struct EthInterface_ {
|
||||||
PcktSieve sieve; ///< Packet sieve
|
PcktSieve sieve; ///< Packet sieve
|
||||||
EthIODef * ioDef; ///< Low-level IO definitions
|
EthIODef *ioDef; ///< Low-level IO definitions
|
||||||
EthernetAddress mac; ///< Ethernet address
|
EthernetAddress mac; ///< Ethernet address
|
||||||
uint32_t capabilities; ///< Ethernet interface capabilities
|
uint32_t capabilities; ///< Ethernet interface capabilities
|
||||||
DhcpState * dhcp; ///< DHCP control block (allocated only, if DHCP operation is initiated)
|
DhcpState *dhcp; ///< DHCP control block (allocated only, if DHCP operation is initiated)
|
||||||
ip4_addr ip; ///< IP address
|
ip4_addr ip; ///< IP address
|
||||||
ip4_addr router; ///< Router IP address
|
ip4_addr router; ///< Router IP address
|
||||||
ip4_addr netmask; ///< Subnet mask
|
ip4_addr netmask; ///< Subnet mask
|
||||||
ip4_addr dns; ///< Domain Name Server
|
ip4_addr dns; ///< Domain Name Server
|
||||||
ArpCache * arpc; ///< ARP cache
|
ArpCache *arpc; ///< ARP cache
|
||||||
ConnBlock arpCb; ///< ARP connection block
|
ConnBlock arpCb; ///< ARP connection block
|
||||||
MsgQueue * txQ; ///< Transmit queue
|
MsgQueue *txQ; ///< Transmit queue
|
||||||
MsgQueue * rxQ; ///< Receive queue
|
MsgQueue *rxQ; ///< Receive queue
|
||||||
ETHLIB_OS_QUEUE_TYPE eventQ; ///< Event queue
|
ETHLIB_OS_QUEUE_TYPE eventQ; ///< Event queue
|
||||||
//ETHLIB_OS_SEM_TYPE eventSem; ///< Event queue semaphore
|
// ETHLIB_OS_SEM_TYPE eventSem; ///< Event queue semaphore
|
||||||
IPv4Assembler * ipra; ///< IPv4 reassembler
|
IPv4Assembler *ipra; ///< IPv4 reassembler
|
||||||
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,7 +99,7 @@ typedef struct EthInterface_ {
|
|||||||
* @param io Low-level IO definitions
|
* @param io Low-level IO definitions
|
||||||
* @return new interface instance
|
* @return new interface instance
|
||||||
*/
|
*/
|
||||||
EthInterface *ethintf_new(EthIODef * io);
|
EthInterface *ethintf_new(EthIODef *io);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receive uncooked packet.
|
* Receive uncooked packet.
|
||||||
@ -113,7 +122,7 @@ void ethinf_push_notification(EthInterface *intf, uint16_t event_code, uint16_t
|
|||||||
* @param event_code pointer to event code
|
* @param event_code pointer to event code
|
||||||
* @param event_data pointer to event data
|
* @param event_data pointer to event data
|
||||||
*/
|
*/
|
||||||
void ethinf_pull_notification(EthInterface *intf, uint16_t * event_code, uint16_t * event_data);
|
void ethinf_pull_notification(EthInterface *intf, uint16_t *event_code, uint16_t *event_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transmit packet.
|
* Transmit packet.
|
||||||
@ -133,38 +142,46 @@ void ethinf_set_capabilities(EthInterface *intf, uint32_t cap);
|
|||||||
* @param idx index of Ethernet event
|
* @param idx index of Ethernet event
|
||||||
* @param cb callback function pointer
|
* @param cb callback function pointer
|
||||||
*/
|
*/
|
||||||
void ethinf_set_event_callback(EthInterface * intf, EthIntfEvIndex idx, EthIntfEvtCb cb);
|
void ethinf_set_event_callback(EthInterface *intf, EthIntfEvIndex idx, EthIntfEvtCb cb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trigger Ethernet event.
|
* Trigger Ethernet event.
|
||||||
* @param intf pointer to Ethernet interface
|
* @param intf pointer to Ethernet interface
|
||||||
* @param idx index of Ethernet interface event
|
* @param idx index of Ethernet interface event
|
||||||
*/
|
*/
|
||||||
void ethinf_trigger_event(EthInterface * intf, EthIntfEvIndex idx);
|
void ethinf_trigger_event(EthInterface *intf, EthIntfEvIndex idx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set link state.
|
* Set link state.
|
||||||
* @param intf pointer to Ethernet interface
|
* @param intf pointer to Ethernet interface
|
||||||
* @param ls link state
|
* @param ls link state
|
||||||
*/
|
*/
|
||||||
void ethinf_set_link_state(EthInterface * intf, bool ls);
|
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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable interface.
|
* Enable interface.
|
||||||
* @param intf pointer to Ethernet interface
|
* @param intf pointer to Ethernet interface
|
||||||
*/
|
*/
|
||||||
void ethinf_up(EthInterface *intf);
|
void ethinf_up(EthInterface *intf);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disable interface.
|
* Disable interface.
|
||||||
* @param intf pointer to Ethernet interface
|
* @param intf pointer to Ethernet interface
|
||||||
*/
|
*/
|
||||||
void ethinf_down(EthInterface *intf);
|
void ethinf_down(EthInterface *intf);
|
||||||
|
|
||||||
#endif //ETHERLIB_ETH_INTERFACE_H
|
/**
|
||||||
|
* 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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user