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

46 lines
1.7 KiB
C

//
// Created by epagris on 2022.12.25..
//
#include "icmp_packet.h"
#include "../../utils.h"
#include "ipv4_packet.h"
int parse_icmp(const uint8_t *hdr, uint32_t size, PcktHeaderElement *pcktHdrLe, struct EthInterface_ *intf, PcktProcFnPassbackData *pb) {
const uint8_t * hdrStart = hdr;
// parse header
IcmpProps *icmpProps = HEADER_FETCH_PROPS(IcmpProps, pcktHdrLe);
FETCH_BYTE_ADVANCE(&icmpProps->type, hdr);
FETCH_BYTE_ADVANCE(&icmpProps->code, hdr);
FETCH_WORD_ADVANCE(&icmpProps->checksum, hdr);
FETCH_WORD_ADVANCE(&icmpProps->identifier, hdr);
FETCH_WORD_ADVANCE(&icmpProps->sequenceNumber, hdr);
// fill-in common fields
IPv4Props * ipProps = HEADER_FETCH_PROPS(IPv4Props, pcktHdrLe->prev);
icmpProps->validityOK = chksum(hdrStart, ipProps->TotalLength - ETH_IPv4_HEADER_SIZE, false) == 0;
icmpProps->containedPacketClass = 0;
icmpProps->headerSize = ETH_ICMP_HEADER_SIZE;
return icmpProps->validityOK ? PROC_FN_RET_OK : PROC_FN_RET_ABORT;
}
void insert_icmp_header(uint8_t *hdr, const PcktHeaderElement *headers, struct EthInterface_ *intf) {
uint8_t * hdrStart = hdr;
IcmpProps *icmpProps = HEADER_FETCH_PROPS(IcmpProps, headers);
FILL_BYTE_ADVANCE(hdr, &icmpProps->type);
FILL_BYTE_ADVANCE(hdr, &icmpProps->code);
uint8_t * ChkSumPtr = hdr;
icmpProps->checksum = 0;
FILL_ADVANCE(hdr, &icmpProps->checksum, 2);
FILL_ADVANCE(hdr, &icmpProps->identifier, 2);
FILL_ADVANCE(hdr, &icmpProps->sequenceNumber, 2);
IPv4Props * ipProps = HEADER_FETCH_PROPS(IPv4Props, headers->prev);
icmpProps->checksum = chksum(hdrStart, ipProps->TotalLength - ETH_IPv4_HEADER_SIZE, false);
FILL_WORD_ADVANCE(ChkSumPtr, icmpProps->checksum);
}