Commit 1ca8eccd authored by 's avatar
Browse files

added MPLS support


git-svn-id: file:///home/svn/mapi/trunk@943 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent bc25fb91
......@@ -88,7 +88,7 @@ void extract_field(struct topx_field *field, unsigned char *ip_pkt, size_t lengt
if (length < sizeof(ip_header))
return;
ip = (ip_header *)ip_pkt;
ip_ver = ip->ver_ihl >> 4;
if (ip_ver == 4)
......@@ -493,6 +493,15 @@ static int topx_cleanup(mapidflib_function_instance_t *instance){
int pktcnt=0;
#define ETHERTYPE_8021Q 0x8100
#define MPLS_MASK 0x8847
struct vlan_802q_header {
u_int16_t priority_cfi_vid;
u_int16_t ether_type;
};
static int topx_process(mapidflib_function_instance_t *instance,
MAPI_UNUSED unsigned char* dev_pkt,
MAPI_UNUSED unsigned char* link_pkt,
......@@ -510,13 +519,27 @@ static int topx_process(mapidflib_function_instance_t *instance,
unsigned int cur_secs = 0;
struct timeval tv;
int linkhdr_len;
uint16_t ethertype;
struct ether_header *ep = NULL;
struct vlan_802q_header *vlan_header = NULL;
switch (instance->hwinfo->link_type) {
case DLT_EN10MB: /* ethernet */
linkhdr_len = sizeof(ether_header);
extract_field(&field, packet + linkhdr_len,
pkt_head->wlen - linkhdr_len, data->protocol, data->field);
break;
linkhdr_len = sizeof(ether_header);
ep = (struct ether_header*)dev_pkt;
ethertype = ntohs(ep->ether_type);
if(ethertype == ETHERTYPE_8021Q) {
linkhdr_len += sizeof(struct vlan_802q_header);
vlan_header = (struct vlan_802q_header*)(dev_pkt + linkhdr_len);
ethertype = ntohs(vlan_header->ether_type);
}
if(ethertype == MPLS_MASK) {
linkhdr_len += 4;
}
extract_field(&field, packet + linkhdr_len,
pkt_head->wlen - linkhdr_len, data->protocol, data->field);
break;
case DLT_CHDLC:
linkhdr_len = 20;
if (ntohs(*(uint16_t*)(dev_pkt + 18)) == ETHERTYPE_IP) {
......
......@@ -228,7 +228,10 @@ static int dc_process(mapidflib_function_instance_t *instance,
p += sizeof(struct vlan_802q_header);
}
if(ethertype != ETHERTYPE_IP) {
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
}
......@@ -280,7 +283,7 @@ static int dc_process(mapidflib_function_instance_t *instance,
}
gettimeofday(&ts, NULL);
for(temp = dclist[hashval]->head, prev = dclist[hashval]->head; temp != NULL; prev = temp, temp = temp->next)
{
if(temp->protocol == iph->protocol &&
......@@ -321,21 +324,25 @@ static int dc_process(mapidflib_function_instance_t *instance,
if(iph->protocol == 6) {
if(p == NULL)
if(p == NULL) {
return 0;
}
if(*p != '$')
if(*p != '$') {
return 0;
}
/* if(p[len - 1] != '|')
return 0;
*/ }
else if(iph->protocol == 17) {
if(p == NULL)
if(p == NULL) {
return 0;
}
if(*p != '$')
if(*p != '$') {
return 0;
}
/* if(p[len - 1] != '|')
return 0;
......@@ -343,19 +350,6 @@ static int dc_process(mapidflib_function_instance_t *instance,
else {
return 0;
}
/* for(i = 0; i < len && i < len; i++) {
if(isprint(p[i])){
printf("%c", p[i]);
}
else if(p[i] == '\n') {
printf(".");
}
else {
printf(".");
}
}
printf("\n\n");
*/
if((i = isDc(instance,pkt,len)) >= 0)
{
......@@ -374,7 +368,6 @@ static int dc_process(mapidflib_function_instance_t *instance,
write_to_log("DC++", found, iph->protocol, source, sp, dest, dp, p_b, len);
#endif
#endif
// printf("DC++ %s %d \n\n",dc_strings[i], iph->protocol);
for(temp = dclist[hashval]->head; temp != NULL; temp = temp->next)
{
......@@ -396,9 +389,9 @@ static int dc_process(mapidflib_function_instance_t *instance,
dclist[hashval]->head = new;
pkt_head->color = DC_COLOR;
return 1;
}
return 0;
}
......
......@@ -319,7 +319,10 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
p += sizeof(struct vlan_802q_header);
}
if(ethertype != ETHERTYPE_IP) {
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
}
......
......@@ -214,7 +214,10 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
p += sizeof(struct vlan_802q_header);
}
if(ethertype != ETHERTYPE_IP) {
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
}
......@@ -278,11 +281,9 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
{
gettimeofday(&(temp->ts), NULL);
//printf("found same\n");
if(iph->protocol == 6 && tcph->fin) {
if(temp == gnulist[hashval]->head) {
gnulist[hashval]->head = temp->next;
//printf("removing from list\n");
}
else {
prev->next = temp->next;
......@@ -309,7 +310,6 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
if((i = isGnutella(instance,pkt,len)) >= 0)
{
//return 1;
new = (struct filters*)malloc(sizeof(struct filters));
if(new == NULL)
printf("new = NULL\n");
......@@ -327,16 +327,6 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
write_to_log("GNUTELLA", found, iph->protocol, source, sp, dest, dp, pkt, len);
#endif
#endif
/*
fprintf(fp, "%d---%s:%d -> ", new->protocol, inet_ntoa(source), sp);
fprintf(fp, " %s:%d\t", inet_ntoa(dest), dp);
for(i = 0; i < 100; i++) {
fprintf(fp, "%c", p[i]);
}
fprintf(fp, "\n\n");
//printf("on port %d -> %d\n", new->sp, new->dp);
*/
for(temp = gnulist[hashval]->head; temp != NULL; temp = temp->next)
{
if(new->protocol == temp->protocol && (
......@@ -346,7 +336,6 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
)
)
{
//printf("exists do not enter\n");
pkt_head->color = GNUTELLA_COLOR;
return 1;
}
......
......@@ -38,6 +38,7 @@
#include <time.h>
#include "log.h"
#include "trackflib.h"
static int ipoverip_init(MAPI_UNUSED mapidflib_function_instance_t *instance, MAPI_UNUSED int fd) {
return 0;
......@@ -70,7 +71,10 @@ static int ipoverip_process(MAPI_UNUSED mapidflib_function_instance_t *instance,
ethertype = ntohs(ep->ether_type);
if(ethertype != ETHERTYPE_IP) {
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
}
......
......@@ -163,7 +163,10 @@ static int irc_process(mapidflib_function_instance_t *instance,
p += sizeof(struct vlan_802q_header);
}
if(ethertype != ETHERTYPE_IP) {
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
}
......
......@@ -86,7 +86,10 @@ static int mapi_process(MAPI_UNUSED mapidflib_function_instance_t *instance,
p += sizeof(struct vlan_802q_header);
}
if(ethertype != ETHERTYPE_IP) {
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
}
......
......@@ -301,7 +301,10 @@ static int trackskype_process(mapidflib_function_instance_t *instance,
p += sizeof(struct vlan_802q_header);
}
if(ethertype != ETHERTYPE_IP) {
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
}
......
......@@ -62,12 +62,12 @@ struct list{
struct filters *tail;
};
#define TOR_STRINGS_NO 14
#define TOR_STRINGS_NO 16
char *torrent_strings[TOR_STRINGS_NO]={"BitTorrent protocol","GET /scrape?info_hash=","GET /announce?info_hash=", "d1:rd2:id20:", "d1:ad2:id20:", "BT_PIECE"
char *torrent_strings[TOR_STRINGS_NO]={"BitTorrent protocol","GET /scrape?info_hash=","GET /announce?info_hash=", "d1:rd2:id20:", "d1:ad2:id20:", "User-Agent: Azureus", "/scrape?info_hash=", "BT_PIECE"
,"BT_REQUEST", "BT_CHOKE", "BT_UNCHOKE", "BT_HAVE", "BT_UNINTERESTED", "BT_INTERESTER", "BT_BITFIELD", "BT_CANCEL"};
int torrent_lens[TOR_STRINGS_NO]={20, 100, 100, 20, 20, 50, 50, 50, 50, 50, 50, 50, 50 , 50};
int torrent_lens[TOR_STRINGS_NO]={20, 100, 100, 20, 20, 100, 100, 50, 50, 50, 50, 50, 50, 50, 50 , 50};
int isTorrent(mapidflib_function_instance_t *, unsigned char *, unsigned int );
......@@ -190,6 +190,23 @@ int isTorrent(mapidflib_function_instance_t *instance, unsigned char *pkt, unsig
}
void print_some_bytes(char *packet, int len)
{
int i = 0;
for(i = 0; i < 100 && i < len; i++) {
if(isprint(packet[i])){
printf("%c", packet[i]);
}
else if(packet[i] == '\n') {
printf(".");
}
else {
printf(".");
}
}
}
static int torrent_process(mapidflib_function_instance_t *instance,
MAPI_UNUSED unsigned char* dev_pkt,
unsigned char* pkt,
......@@ -244,8 +261,12 @@ static int torrent_process(mapidflib_function_instance_t *instance,
ethertype = ntohs(vlan_header->ether_type);
p += sizeof(struct vlan_802q_header);
}
if(ethertype != ETHERTYPE_IP) {
if(ethertype == MPLS_MASK) {
printf("Got MPLS\n");
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
}
......@@ -305,30 +326,7 @@ static int torrent_process(mapidflib_function_instance_t *instance,
if(sp == 4662 || dp == 4662) { // eDonkey
return 0;
}
/*
{
struct edonkey_header *edonkey_h;
if(iph->protocol == 6) {
edonkey_h = (struct edonkey_header *)p;
if(edonkey_h->protocol != (char)0xE3 && edonkey_h->protocol != (char)0xC5 && edonkey_h->protocol != (char)0xd4) {
if(getSize(edonkey_h->size) != (pkt_head->wlen - ether_len - ip_len - tcp_len - 5))
if(isEdonkey(iph->protocol, edonkey_h->type) == 0)
return 0;
}
}
else if(iph->protocol == 17) {
edonkey_h = (struct edonkey_header *)p;
if(edonkey_h->protocol != (char)0xe3 && edonkey_h->protocol != (char)0xC5 && edonkey_h->protocol != (char)0xd4) {
if(getSize(edonkey_h->size) != (pkt_head->caplen - ether_len - ip_len - udp_len - 5))
if(isEdonkey(iph->protocol, edonkey_h->size[0]) == 0)
return 0;
}
}
}
*/
if(sp == 411 || dp == 411) { // DC++
return 0;
}
......@@ -365,6 +363,7 @@ static int torrent_process(mapidflib_function_instance_t *instance,
temp->byte_counter = 0;
}
pkt_head->color = TORRENT_COLOR;
return 1;
}
......@@ -404,17 +403,6 @@ static int torrent_process(mapidflib_function_instance_t *instance,
#endif
#endif
/*
if(sp == 22 || dp == 22) {
printf("tcp len: %d %d %d\n", tcph->doff * 4, iph->tot_len ,pkt_head->wlen );
printf("possitive categorising packet---> %s %d---%s:%d -> ", torrent_strings[i], iph->protocol, inet_ntoa(source), sp);
printf(" %s:%d\n", inet_ntoa(dest), dp);
for(i = 0; i < 100; i++) {
printf("%c", p[i]);
}
printf("\n\n");
}
*/
for(temp = torlist[hashval]->head; temp != NULL; temp = temp->next)
{
if(new->protocol == temp->protocol && (
......@@ -436,9 +424,9 @@ static int torrent_process(mapidflib_function_instance_t *instance,
torlist[hashval]->head = new;
pkt_head->color = TORRENT_COLOR;
return 1;
}
return 0;
}
......
......@@ -2,6 +2,7 @@
#define __TRACKLIB_H__
#define ETHERTYPE_8021Q 0x8100
#define MPLS_MASK 0x8847
#define HASHTABLESIZE 4096
//#define __WITH_AHO__
......
......@@ -131,7 +131,10 @@ static int trackftp_process(mapidflib_function_instance_t *instance,
p += sizeof(struct vlan_802q_header);
}
if(ethertype != ETHERTYPE_IP) {
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 0;
}
......
......@@ -86,7 +86,10 @@ static int web_process(MAPI_UNUSED mapidflib_function_instance_t *instance,
p += sizeof(struct vlan_802q_header);
}
if(ethertype != ETHERTYPE_IP) {
if(ethertype == MPLS_MASK) {
p += 4;
}
else if(ethertype != ETHERTYPE_IP) {
return 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