- IGMPv2 capabilities added (report membership, leave group) - ICMP capabilities added (ping) - Tx Message Queue added
44 lines
1.6 KiB
C
44 lines
1.6 KiB
C
//
|
|
// Created by epagris on 2022.11.07..
|
|
//
|
|
|
|
#include "ipv4_connblock.h"
|
|
|
|
#include "../packet_parsers/packet_parsers.h"
|
|
#include "../../utils.h"
|
|
|
|
static bool filtIPv4(const PcktSieveFilterCondition *filtCond, const PcktProps *contProps, const PcktProps *ownProps, EthInterface * intf) {
|
|
EthernetProps *etherProps = (EthernetProps *) contProps;
|
|
IPv4Props *ipProps = (IPv4Props *) ownProps;
|
|
|
|
return etherProps->length_type == ETH_IPv4_PACKET_CLASS && ((IP_ADDR_FROM_FILTCOND(filtCond) == ipProps->DestIPAddr) ||
|
|
((IP_ADDR_FROM_FILTCOND(filtCond) == IPv4_IF_ADDR) && (ipProps->DestIPAddr == intf->ip) && (intf->ip != 0)));
|
|
}
|
|
|
|
ConnBlock ipv4_new_connblock(EthInterface *intf, ip4_addr ipAddr, SieveCallBackFn cbFn) {
|
|
ConnBlock connb;
|
|
PcktSieveFilterCondition filtCond;
|
|
packfiltcond_zero(&filtCond);
|
|
IP_ADDR_TO_FILTCOND(&filtCond, ipAddr);
|
|
PcktSieveLayerTag tag;
|
|
tag.u = 0;
|
|
bool matchAny = ipAddr == IPv4_ANY_ADDR;
|
|
connb.sieveLayer = packsieve_new_layer(&intf->sieve.layer0, &filtCond, matchAny, filtIPv4, cbFn, tag, ETH_IPv4_PACKET_CLASS);
|
|
ASSERT_NULL(connb.sieveLayer);
|
|
|
|
connb.intf = intf;
|
|
|
|
if (!matchAny) {
|
|
if (ipAddr != IPv4_IF_ADDR) {
|
|
SNPRINTF(connb.sieveLayer->infoTag, PCKT_SIEVE_INFOTAG_LEN, "IP: %u.%u.%u.%u",
|
|
(ipAddr & 0xFF), ((ipAddr >> 8) & 0xFF), ((ipAddr >> 16) & 0xFF), ((ipAddr >> 24) & 0xFF));
|
|
} else {
|
|
SNPRINTF(connb.sieveLayer->infoTag, PCKT_SIEVE_INFOTAG_LEN, "IP: INTF. ADDR.");
|
|
}
|
|
} else {
|
|
SNPRINTF(connb.sieveLayer->infoTag, PCKT_SIEVE_INFOTAG_LEN, "IP: ANY");
|
|
}
|
|
|
|
return connb;
|
|
}
|