Commit 7d223639 authored by 's avatar

Added basic support for POS protocol.


git-svn-id: file:///home/svn/mapi/trunk@1394 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent bcf18b6c
......@@ -6,6 +6,7 @@
#include <sys/shm.h>
#include <string.h>
#include <errno.h>
#include "mapidflib.h"
#include "mapidlib.h"
#include "mapidevices.h"
......@@ -17,8 +18,7 @@
#include "acsmx2.h"
#include "mapi_errors.h"
#include <stdio.h>
#include <stdlib.h>
#include <pcap.h>
#include <netinet/in.h>
#include <net/ethernet.h>
#include <netinet/ip.h>
......@@ -35,7 +35,6 @@
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <time.h>
......@@ -192,6 +191,10 @@ static int dc_process(mapidflib_function_instance_t *instance,
struct list **dclist = ((struct mapid_dc*)instance->internal_data)->dclist;
uint16_t ethertype;
struct ether_header *ep = NULL;
struct pos_header {
uint16_t af;
uint16_t cf;
} *pp = NULL;
struct iphdr *iph = NULL;
struct tcphdr *tcph = NULL;
struct udphdr *udph = NULL;
......@@ -211,28 +214,48 @@ static int dc_process(mapidflib_function_instance_t *instance,
if(pkt_color != 0 && pkt_color != DC_COLOR) {
return 0;
}
p = pkt;
// lay the Ethernet header struct over the packet data
ep = (struct ether_header *)p;
switch(instance->hwinfo->link_type) {
case DLT_EN10MB:
// lay the Ethernet header struct over the packet data
ep = (struct ether_header *)p;
// skip ethernet header
p += sizeof(struct ether_header);
len -= sizeof(struct ether_header);
// skip ethernet header
p += sizeof(struct ether_header);
len -= sizeof(struct ether_header);
ethertype = ntohs(ep->ether_type);
ethertype = ntohs(ep->ether_type);
if(ethertype == ETHERTYPE_8021Q) {
vlan_header = (struct vlan_802q_header*)p;
ethertype = ntohs(vlan_header->ether_type);
p += sizeof(struct vlan_802q_header);
}
if(ethertype == ETHERTYPE_8021Q) {
vlan_header = (struct vlan_802q_header*)p;
ethertype = ntohs(vlan_header->ether_type);
p += sizeof(struct vlan_802q_header);
}
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
}
break;
case DLT_CHDLC:
pp = (struct pos_header *)p;
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
p += sizeof(struct pos_header);
len -= sizeof(struct pos_header);
ethertype = ntohs(pp->cf);
if (ethertype != ETHERTYPE_IP) {
return 0;
}
break;
default:
//DEBUG_CMD(Debug_Message("Link layer not supported"));
return 0;
}
// IP header struct over the packet data;
......
......@@ -7,6 +7,7 @@
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "mapidflib.h"
#include "mapidlib.h"
#include "mapidevices.h"
......@@ -15,6 +16,8 @@
#include "debug.h"
#include "mapiipc.h"
#include "mstring.h"
#include <pcap.h>
#include <netinet/in.h>
#include <net/ethernet.h>
#include <netinet/ip.h>
......@@ -277,6 +280,10 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
struct list **edonkeylist = ((struct mapid_edonkey*)instance->internal_data)->edonkeylist;
uint16_t ethertype;
struct ether_header *ep = NULL;
struct pos_header {
uint16_t af;
uint16_t cf;
} *pp = NULL;
struct iphdr *iph = NULL;
struct tcphdr *tcph = NULL;
struct udphdr *udph = NULL;
......@@ -303,27 +310,47 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
p = pkt;
// lay the Ethernet header struct over the packet data
ep = (struct ether_header *)p;
ether_len = sizeof(struct ether_header);
switch(instance->hwinfo->link_type) {
case DLT_EN10MB:
// lay the Ethernet header struct over the packet data
ep = (struct ether_header *)p;
ether_len = sizeof(struct ether_header);
// skip ethernet header
p += sizeof(struct ether_header);
len -= sizeof(struct ether_header);
// skip ethernet header
p += sizeof(struct ether_header);
len -= sizeof(struct ether_header);
ethertype = ntohs(ep->ether_type);
ethertype = ntohs(ep->ether_type);
if(ethertype == ETHERTYPE_8021Q) {
vlan_header = (struct vlan_802q_header*)p;
ethertype = ntohs(vlan_header->ether_type);
p += sizeof(struct vlan_802q_header);
}
if(ethertype == ETHERTYPE_8021Q) {
vlan_header = (struct vlan_802q_header*)p;
ethertype = ntohs(vlan_header->ether_type);
p += sizeof(struct vlan_802q_header);
}
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
}
break;
case DLT_CHDLC:
pp = (struct pos_header *)p;
ether_len = sizeof(struct pos_header);
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
p += sizeof(struct pos_header);
len -= sizeof(struct pos_header);
ethertype = ntohs(pp->cf);
if (ethertype != ETHERTYPE_IP) {
return 0;
}
break;
default:
//DEBUG_CMD(Debug_Message("Link layer not supported"));
return 0;
}
// IP header struct over the packet data;
......
......@@ -6,6 +6,7 @@
#include <sys/shm.h>
#include <string.h>
#include <errno.h>
#include "mapidflib.h"
#include "mapidlib.h"
#include "mapidevices.h"
......@@ -17,8 +18,7 @@
#include "acsmx2.h"
#include "mapi_errors.h"
#include <stdio.h>
#include <stdlib.h>
#include <pcap.h>
#include <netinet/in.h>
#include <net/ethernet.h>
#include <netinet/ip.h>
......@@ -35,7 +35,6 @@
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <time.h>
......@@ -177,6 +176,10 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
struct list **gnulist = ((struct mapid_gnutella*)instance->internal_data)->gnulist;
uint16_t ethertype;
struct ether_header *ep = NULL;
struct pos_header {
uint16_t af;
uint16_t cf;
} *pp = NULL;
struct iphdr *iph = NULL;
struct tcphdr *tcph = NULL;
struct udphdr *udph = NULL;
......@@ -199,26 +202,45 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
p = pkt;
// lay the Ethernet header struct over the packet data
ep = (struct ether_header *)p;
switch(instance->hwinfo->link_type) {
case DLT_EN10MB:
// lay the Ethernet header struct over the packet data
ep = (struct ether_header *)p;
// skip ethernet header
p += sizeof(struct ether_header);
len -= sizeof(struct ether_header);
// skip ethernet header
p += sizeof(struct ether_header);
len -= sizeof(struct ether_header);
ethertype = ntohs(ep->ether_type);
ethertype = ntohs(ep->ether_type);
if(ethertype == ETHERTYPE_8021Q) {
vlan_header = (struct vlan_802q_header*)p;
ethertype = ntohs(vlan_header->ether_type);
p += sizeof(struct vlan_802q_header);
}
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
if(ethertype == ETHERTYPE_8021Q) {
vlan_header = (struct vlan_802q_header*)p;
ethertype = ntohs(vlan_header->ether_type);
p += sizeof(struct vlan_802q_header);
}
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
}
break;
case DLT_CHDLC:
pp = (struct pos_header *)p;
p += sizeof(struct pos_header);
len -= sizeof(struct pos_header);
ethertype = ntohs(pp->cf);
if (ethertype != ETHERTYPE_IP) {
return 0;
}
break;
default:
//DEBUG_CMD(Debug_Message("Link layer not supported"));
return 0;
}
// IP header struct over the packet data;
......
......@@ -6,6 +6,7 @@
#include <sys/shm.h>
#include <string.h>
#include <errno.h>
#include "mapidflib.h"
#include "mapidlib.h"
#include "mapidevices.h"
......@@ -14,8 +15,8 @@
#include "debug.h"
#include "mapiipc.h"
#include "mstring.h"
#include <stdio.h>
#include <stdlib.h>
#include <pcap.h>
#include <netinet/in.h>
#include <net/ethernet.h>
#include <netinet/ip.h>
......@@ -32,7 +33,6 @@
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <time.h>
......@@ -101,6 +101,10 @@ static int gridftp_process(mapidflib_function_instance_t *instance,
struct list **cntlist = ((struct mapid_ftp*)instance->internal_data)->cntlist;
uint16_t ethertype;
struct ether_header *ep = NULL;
struct pos_header {
uint16_t af;
uint16_t cf;
} *pp = NULL;
struct iphdr *iph = NULL;
struct tcphdr *tcph = NULL;
......@@ -119,26 +123,45 @@ static int gridftp_process(mapidflib_function_instance_t *instance,
}
p = pkt;
// lay the Ethernet header struct over the packet data
ep = (struct ether_header *)p;
switch(instance->hwinfo->link_type) {
case DLT_EN10MB:
// lay the Ethernet header struct over the packet data
ep = (struct ether_header *)p;
// skip ethernet header
p += sizeof(struct ether_header);
len -= sizeof(struct ether_header);
// skip ethernet header
p += sizeof(struct ether_header);
len -= sizeof(struct ether_header);
ethertype = ntohs(ep->ether_type);
if(ethertype == ETHERTYPE_8021Q) {
vlan_header = (struct vlan_802q_header*)p;
ethertype = ntohs(vlan_header->ether_type);
p += sizeof(struct vlan_802q_header);
}
ethertype = ntohs(ep->ether_type);
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
if(ethertype == ETHERTYPE_8021Q) {
vlan_header = (struct vlan_802q_header*)p;
ethertype = ntohs(vlan_header->ether_type);
p += sizeof(struct vlan_802q_header);
}
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
}
break;
case DLT_CHDLC:
pp = (struct pos_header *)p;
p += sizeof(struct pos_header);
len -= sizeof(struct pos_header);
ethertype = ntohs(pp->cf);
if (ethertype != ETHERTYPE_IP) {
return 0;
}
break;
default:
//DEBUG_CMD(Debug_Message("Link layer not supported"));
return 0;
}
// IP header struct over the packet data;
......
......@@ -6,6 +6,7 @@
#include <sys/shm.h>
#include <string.h>
#include <errno.h>
#include "mapidflib.h"
#include "mapidlib.h"
#include "mapidevices.h"
......@@ -14,8 +15,8 @@
#include "debug.h"
#include "mapiipc.h"
#include "mstring.h"
#include <stdio.h>
#include <stdlib.h>
#include <pcap.h>
#include <netinet/in.h>
#include <net/ethernet.h>
#include <netinet/ip.h>
......@@ -32,7 +33,6 @@
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <time.h>
......@@ -132,6 +132,10 @@ static int irc_process(mapidflib_function_instance_t *instance,
struct list **irclist = ((struct mapid_irc*)instance->internal_data)->irclist;
uint16_t ethertype;
struct ether_header *ep = NULL;
struct pos_header {
uint16_t af;
uint16_t cf;
} *pp = NULL;
struct iphdr *iph = NULL;
struct tcphdr *tcph = NULL;
struct udphdr *udph = NULL;
......@@ -148,26 +152,45 @@ static int irc_process(mapidflib_function_instance_t *instance,
p = pkt;
// lay the Ethernet header struct over the packet data
ep = (struct ether_header *)p;
switch(instance->hwinfo->link_type) {
case DLT_EN10MB:
// lay the Ethernet header struct over the packet data
ep = (struct ether_header *)p;
// skip ethernet header
p += sizeof(struct ether_header);
len -= sizeof(struct ether_header);
// skip ethernet header
p += sizeof(struct ether_header);
len -= sizeof(struct ether_header);
ethertype = ntohs(ep->ether_type);
ethertype = ntohs(ep->ether_type);
if(ethertype == ETHERTYPE_8021Q) {
vlan_header = (struct vlan_802q_header*)p;
ethertype = ntohs(vlan_header->ether_type);
p += sizeof(struct vlan_802q_header);
}
if(ethertype == ETHERTYPE_8021Q) {
vlan_header = (struct vlan_802q_header*)p;
ethertype = ntohs(vlan_header->ether_type);
p += sizeof(struct vlan_802q_header);
}
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
}
break;
case DLT_CHDLC:
pp = (struct pos_header *)p;
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
p += sizeof(struct pos_header);
len -= sizeof(struct pos_header);
ethertype = ntohs(pp->cf);
if (ethertype != ETHERTYPE_IP) {
return 0;
}
break;
default:
//DEBUG_CMD(Debug_Message("Link layer not supported"));
return 0;
}
// IP header struct over the packet data;
......
......@@ -6,6 +6,7 @@
#include <sys/shm.h>
#include <string.h>
#include <errno.h>
#include "mapidflib.h"
#include "mapidlib.h"
#include "mapidevices.h"
......@@ -14,8 +15,8 @@
#include "debug.h"
#include "mapiipc.h"
#include "mstring.h"
#include <stdio.h>
#include <stdlib.h>
#include <pcap.h>
#include <netinet/in.h>
#include <net/ethernet.h>
#include <netinet/ip.h>
......@@ -32,7 +33,6 @@
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/time.h>
......@@ -272,6 +272,10 @@ static int trackskype_process(mapidflib_function_instance_t *instance,
struct list **cntlist = ((struct mapid_skype*)instance->internal_data)->cntlist;
uint16_t ethertype;
struct ether_header *ep = NULL;
struct pos_header {
uint16_t af;
uint16_t cf;
} *pp = NULL;
struct iphdr *iph = NULL;
struct tcphdr *tcph = NULL;
struct udphdr *udph = NULL;
......@@ -293,28 +297,48 @@ static int trackskype_process(mapidflib_function_instance_t *instance,
if(pkt_color != 0 && pkt_color != SKYPE_COLOR) {
return 0;
}
p = pkt;
// lay the Ethernet header struct over the packet data
ep = (struct ether_header *)p;
switch(instance->hwinfo->link_type) {
case DLT_EN10MB:
// lay the Ethernet header struct over the packet data
ep = (struct ether_header *)p;
// skip ethernet header
p += sizeof(struct ether_header);
len -= sizeof(struct ether_header);
// skip ethernet header
p += sizeof(struct ether_header);
len -= sizeof(struct ether_header);
ethertype = ntohs(ep->ether_type);
if(ethertype == ETHERTYPE_8021Q) {
vlan_header = (struct vlan_802q_header*)p;
ethertype = ntohs(vlan_header->ether_type);
p += sizeof(struct vlan_802q_header);
}
ethertype = ntohs(ep->ether_type);
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
if(ethertype == ETHERTYPE_8021Q) {
vlan_header = (struct vlan_802q_header*)p;
ethertype = ntohs(vlan_header->ether_type);
p += sizeof(struct vlan_802q_header);
}
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
}
break;
case DLT_CHDLC:
pp = (struct pos_header *)p;
p += sizeof(struct pos_header);
len -= sizeof(struct pos_header);
ethertype = ntohs(pp->cf);
if (ethertype != ETHERTYPE_IP) {
return 0;
}
break;
default:
//DEBUG_CMD(Debug_Message("Link layer not supported"));
return 0;
}
// IP header struct over the packet data;
......
......@@ -18,8 +18,7 @@
#include "acsmx2.h"
#include "mapi_errors.h"
#include <stdio.h>
#include <stdlib.h>
#include <pcap.h>
#include <netinet/in.h>
#include <net/ethernet.h>
#include <netinet/ip.h>
......@@ -36,7 +35,6 @@
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <time.h>
......@@ -220,6 +218,10 @@ static int torrent_process(mapidflib_function_instance_t *instance,
struct list **torlist = ((struct mapid_torrent*)instance->internal_data)->torlist;
uint16_t ethertype;
struct ether_header *ep = NULL;
struct pos_header {
uint16_t af;
uint16_t cf;
} *pp = NULL;
struct iphdr *iph = NULL;
struct tcphdr *tcph = NULL;
struct udphdr *udph = NULL;
......@@ -235,7 +237,7 @@ static int torrent_process(mapidflib_function_instance_t *instance,
int i = 0;
int ether_len =0 , ip_len = 0, tcp_len = 0, udp_len = 0;
int ip_len = 0, tcp_len = 0, udp_len = 0;
int pkt_color = pkt_head->color;
......@@ -244,29 +246,99 @@ static int torrent_process(mapidflib_function_instance_t *instance,
}
p = pkt;
/*
typedef struct flags {
uint8_t iface:2;
uint8_t vlen:1;
uint8_t trunc:1;
uint8_t rxerror:1;
uint8_t dserror:1;
uint8_t reserved:1;
uint8_t direction:1;
} flags_t;
typedef struct dag_record {
uint64_t ts;
uint8_t type;
flags_t flags;
uint16_t rlen;
uint16_t lctr;
uint16_t wlen;
union {
pos_rec_t pos;
eth_rec_t eth;
atm_rec_t atm;
aal5_rec_t aal5;
aal2_rec_t aal2;
mc_hdlc_rec_t mc_hdlc;
mc_raw_rec_t mc_raw;
mc_atm_rec_t mc_atm;
mc_aal_rec_t mc_aal5;
mc_aal_rec_t mc_aal2;
mc_raw_channel_rec_t mc_raw_channel;
} rec;
} dag_record_t;
typedef struct pos_rec {
uint32_t hdlc;
uint8_t pload[1];
} pos_rec_t;
typedef struct eth_rec {
uint8_t offset;
uint8_t pad;
uint8_t dst[6];
uint8_t src[6];
uint16_t etype;
uint8_t pload[1];
} eth_rec_t;
typedef struct mc_hdlc_rec {
uint32_t mc_header;
uint8_t pload[1];
} mc_hdlc_rec_t;
*/
switch(instance->hwinfo->link_type) {
case DLT_EN10MB:
// lay the Ethernet header struct over the packet data
ep = (struct ether_header *)p;
// skip ethernet header
p += sizeof(struct ether_header);
len -= sizeof(struct ether_header);
ethertype = ntohs(ep->ether_type);
if(ethertype == ETHERTYPE_8021Q) {
vlan_header = (struct vlan_802q_header*)p;
ethertype = ntohs(vlan_header->ether_type);
p += sizeof(struct vlan_802q_header);
}
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
}
break;
case DLT_CHDLC:
pp = (struct pos_header *)p;
// lay the Ethernet header struct over the packet data
ep = (struct ether_header *)p;
ether_len = sizeof(struct ether_header);
// skip ethernet header
p += sizeof(struct ether_header);
len -= sizeof(struct ether_header);
p += sizeof(struct pos_header);
len -= sizeof(struct pos_header);
ethertype = ntohs(ep->ether_type);
ethertype = ntohs(pp->cf);
if(ethertype == ETHERTYPE_8021Q) {
vlan_header = (struct vlan_802q_header*)p;
ethertype = ntohs(vlan_header->ether_type);
p += sizeof(struct vlan_802q_header);
}
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
if (ethertype != ETHERTYPE_IP) {
return 0;
}
break;
default:
//DEBUG_CMD(Debug_Message("Link layer not supported"));
return 0;
}
// IP header struct over the packet data;
......
......@@ -6,6 +6,7 @@
#include <sys/shm.h>
#include <string.h>
#include <errno.h>
#include "mapidflib.h"
#include "mapidlib.h"
#include "mapidevices.h"
......@@ -14,8 +15,8 @@
#include "debug.h"