Commit 733751ac authored by 's avatar
Browse files

added support for POS-network packets.


git-svn-id: file:///home/svn/mapi/trunk@883 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 47769602
......@@ -22,10 +22,6 @@
#include "mapid.h"
#include "fhelp.h"
#ifndef CHDLC_HDRLEN
#define CHDLC_HDRLEN 4
#endif
static int hash_init(mapidflib_function_instance_t * instance,
MAPI_UNUSED int fd)
//Initializes the function
......@@ -70,7 +66,6 @@ static int hash_process(mapidflib_function_instance_t * instance,
unsigned char *data = 0x00; // data to hash
unsigned int datalen = 0;
unsigned int linkhdr_len;
len = pkt_head->caplen; // entire packet's length
......@@ -86,19 +81,18 @@ static int hash_process(mapidflib_function_instance_t * instance,
return MFUNCT_INVALID_ARGUMENT_1;
}
if (instance->hwinfo->link_type == DLT_EN10MB) /* ethernet */ {
linkhdr_len = sizeof(struct ether_header);
} else /* DLT_CHDLC */ {
linkhdr_len = CHDLC_HDRLEN;
}
if (option == 0) { // hash entire device packet
data = dev_pkt;
datalen = pkt_head->caplen;
}
else if (option == 1) {
datalen = pkt_head->caplen - linkhdr_len;
data = (u_char*)(dev_pkt + linkhdr_len);
if (instance->hwinfo->link_type == DLT_EN10MB) /* ethernet */ {
datalen = pkt_head->caplen - sizeof(struct ether_header);
data = (u_char*)(dev_pkt + sizeof(struct ether_header));
} else if (instance->hwinfo->link_type == DLT_CHDLC) {
datalen = pkt_head->caplen - 20;
data = (u_char*)(dev_pkt + 20);
}
}
else if (option == 2) { // hash IP/ARP/RARP payload
if (instance->hwinfo->link_type == DLT_EN10MB) /* ethernet */ {
......@@ -110,8 +104,8 @@ static int hash_process(mapidflib_function_instance_t * instance,
}
else if (ntohs(eth->ether_type) == ETHERTYPE_ARP
|| ntohs(eth->ether_type) == ETHERTYPE_REVARP) {
arph = (struct arphdr *) (dev_pkt + linkhdr_len);
datalen = pkt_head->caplen - linkhdr_len - sizeof(struct arphdr);
arph = (struct arphdr *) (dev_pkt + sizeof(struct ether_header));
datalen = pkt_head->caplen - sizeof(struct ether_header) - sizeof(struct arphdr);
data = (u_char *) arph + sizeof(struct arphdr);
}
else {
......@@ -120,15 +114,15 @@ static int hash_process(mapidflib_function_instance_t * instance,
}
}
else if (instance->hwinfo->link_type == DLT_CHDLC) { /* CHDLC */
if ((u_int32_t)ntohl(*(const u_int32_t *)(&data[2])) == ETHERTYPE_IP) {
iph = (struct iphdr *) (dev_pkt + linkhdr_len);
if (ntohs(*(uint16_t*)(dev_pkt + 18)) == ETHERTYPE_IP) {
iph = (struct iphdr *) (dev_pkt + 20);
datalen = ntohs(iph->tot_len) - (iph->ihl << 2);
data = (u_char *) iph + (iph->ihl << 2);
}
else if ((u_int32_t)ntohl(*(const u_int32_t *)(&data[2])) == ETHERTYPE_ARP
|| (u_int32_t)ntohl(*(const u_int32_t *)(&data[2])) == ETHERTYPE_REVARP) {
arph = (struct arphdr *) (dev_pkt + linkhdr_len);
datalen = pkt_head->caplen - linkhdr_len - sizeof(struct arphdr);
else if (ntohs(*(uint16_t*)(dev_pkt + 18)) == ETHERTYPE_ARP
|| ntohs(*(uint16_t*)(dev_pkt + 18)) == ETHERTYPE_REVARP) {
arph = (struct arphdr *) (dev_pkt + 20);
datalen = pkt_head->caplen - 20 - sizeof(struct arphdr);
data = (u_char *) arph + sizeof(struct arphdr);
}
else {
......@@ -142,9 +136,14 @@ static int hash_process(mapidflib_function_instance_t * instance,
}
else if (option == 3) { // hash TCP/UDP/ICMP payload
eth = (struct ether_header *)link_pkt;
if (((instance->hwinfo->link_type == DLT_EN10MB) && ntohs(eth->ether_type) == ETHERTYPE_IP)
|| instance->hwinfo->link_type == DLT_CHDLC) {
iph = (struct iphdr *)(dev_pkt + linkhdr_len);
if ((instance->hwinfo->link_type == DLT_EN10MB && ntohs(eth->ether_type) == ETHERTYPE_IP)
|| (instance->hwinfo->link_type == DLT_CHDLC && ntohs(*(uint16_t*)(dev_pkt + 18)) == ETHERTYPE_IP)) {
if (instance->hwinfo->link_type == DLT_EN10MB) {
iph = (struct iphdr *)(dev_pkt + sizeof(struct ether_header));
} else if (instance->hwinfo->link_type == DLT_CHDLC) {
iph = (struct iphdr *) (dev_pkt + 20);
}
switch (iph->protocol) {
case IPPROTO_TCP:
tcph = (struct tcphdr*)((u_char*)iph + (iph->ihl << 2));
......@@ -181,7 +180,7 @@ static int hash_process(mapidflib_function_instance_t * instance,
}
hash = hash % prime;
ptr = (unsigned int *) instance->result.data;
ptr = (unsigned int *) (instance->result.data);
(*ptr) = hash;
return 1;
......
......@@ -21,10 +21,6 @@
#include <net/ethernet.h> /* For ETHERTYPE_IP */
#include "debug.h"
#ifndef CHDLC_HDRLEN
#define CHDLC_HDRLEN 4
#endif
#define NUM_STATS 40
//Hashing based sampling
......@@ -207,11 +203,11 @@ static int hashsamp_process(mapidflib_function_instance_t *instance,
data=data+14; //ethernet header is 14bytes
} else if (instance->hwinfo->link_type == DLT_CHDLC ) {
data = (const char*)pkt;
if ((u_int32_t)ntohl(*(const u_int32_t *)(&data[2])) != ETHERTYPE_IP) {
//this is not an IP packet
return 0;
if (ntohs(*(uint16_t*)(dev_pkt + 18)) != ETHERTYPE_IP) {
//this is not an IP packet
return 0;
}
data = data + CHDLC_HDRLEN;
data=data+20;
} else {
assert(0);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment