EtherLib/prefab/packet_parsers/ethernet_frame.h
Wiesner András ab8d45932f Timestamping and bunch of bugfix and optimization
- Timestamping management added
- Errors due to reading uninitialized data in ARP fixed
- EthInterface reworked, incoming packet notification and payload readout separated (through which fixing concurrent access problems)
- RX and TX offloads added
- Capability to add a packet sieve layer without prior registration of specific packet class added (this makes it possible to register arbitrary EtherType connection blocks, for example)
2023-04-27 09:38:26 +02:00

55 lines
1.6 KiB
C

//
// Created by epagris on 2022.11.03..
//
#ifndef ETHERLIB_ETHERNET_FRAME_H
#define ETHERLIB_ETHERNET_FRAME_H
#include <stdint.h>
#include "../../packet_registry.h"
#include "../../packet_sieve.h"
#define ETH_HW_ADDR_LEN (6)
#define ETH_ETHERNET_HEADER_SIZE (14)
#define HEADER_FETCH_PROPS(T,h) (T *)(&((h)->props))
#define ALLOC_HEADER_ELEMENT(T) (PcktHeaderElement *) dynmem_alloc(ETH_PCKT_HEADER_ELEMENT_HEAD_SIZE + sizeof(T))
#define HWACPY(dst,src) memcpy((dst),(src), ETH_HW_ADDR_LEN)
typedef uint8_t EthernetAddress[ETH_HW_ADDR_LEN];
extern EthernetAddress ETH_ETHERNET_IPMC_HWADDR;
/**
* @struct EthernetProps
* Ethernet frame properties
*/
typedef struct {
PcktPropsHeader;
EthernetAddress destAddr; ///< destination address
EthernetAddress sourceAddr; ///< source address
uint16_t length_type; ///< frame length_type
} EthernetProps;
struct EthInterface_;
/**
* Parse raw Ethernet frames.
* @param hdr pointer to the Ethernet packet header
* @param size total frame size
* @param pcktHdrLe pointer to property storage
* @return EtherType or 0 (if size is less than 1500) on success or -1 on error
*/
int parse_ethernet(const uint8_t *hdr, uint32_t size, PcktHeaderElement *pcktHdrLe, struct EthInterface_ *intf, PcktProcFnPassbackData * pb);
/**
* Insert Ethernet header to specified address.
* @param hdr space where the header is to be inserted
* @param headers linked list of header, top is always relevant
*/
void insert_ethernet_header(uint8_t *hdr, const PcktHeaderElement *headers, struct EthInterface_ *intf);
#endif //ETHERLIB_ETHERNET_FRAME_H