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

59 lines
1.9 KiB
C

//
// Created by epagris on 2022.12.25..
//
#include "igmp_packet.h"
#include "../../utils.h"
//static uint16_t igmp_chksum(const uint8_t * hdr) {
// // sum fields
// uint32_t sum = 0;
// const uint16_t *pField = (const uint16_t *) hdr;
// for (uint8_t i = 0; i < (ETH_IGMP_HEADER_SIZE / sizeof(uint16_t)); i++) {
// uint16_t field = pField[i];
// if (i != 1) { // 6. 16-bit long field is the checksum itself, do not count in
// sum += field;
// }
// }
//
// while (sum >> 16) {
// sum = (sum & 0xFFFF) + (sum >> 16);
// }
//
// // invert result
// uint16_t sum16 = sum ^ 0xFFFF;
// return sum16;
//}
void insert_igmp_header(uint8_t *hdr, const PcktHeaderElement *headers, struct EthInterface_ *intf) {
IgmpProps *igmpProps = HEADER_FETCH_PROPS(IgmpProps, headers);
uint8_t * hdrBeg = hdr;
FILL_ADVANCE(hdr, &igmpProps->type, 1);
FILL_ADVANCE(hdr, &igmpProps->maxRespTime, 1);
uint8_t * ChkSumPtr = hdr;
igmpProps->checksum = 0;
FILL_WORD_ADVANCE(hdr, igmpProps->checksum);
FILL_DWORD_ADVANCE(hdr, igmpProps->groupAddr);
igmpProps->checksum = chksum(hdrBeg, ETH_IGMP_HEADER_SIZE, false);
memcpy(ChkSumPtr, &igmpProps->checksum, 2);
}
int parse_igmp(const uint8_t *hdr, uint32_t size, PcktHeaderElement *pcktHdrLe, struct EthInterface_ *intf, PcktProcFnPassbackData *pb) {
// parse header
IgmpProps *igmpProps = HEADER_FETCH_PROPS(IgmpProps, pcktHdrLe);
FETCH_BYTE_ADVANCE(&igmpProps->type, hdr);
FETCH_BYTE_ADVANCE(&igmpProps->maxRespTime, hdr);
FETCH_WORD_ADVANCE(&igmpProps->checksum, hdr);
FETCH_WORD_ADVANCE(&igmpProps->groupAddr, hdr);
// fill-in common fields
uint16_t calcChkSum = chksum(hdr, ETH_IGMP_HEADER_SIZE, false);
igmpProps->validityOK = (calcChkSum == 0);
igmpProps->containedPacketClass = 0;
igmpProps->headerSize = ETH_IGMP_HEADER_SIZE;
return igmpProps->validityOK ? PROC_FN_RET_OK : PROC_FN_RET_ABORT;
}