Commit 46999478 authored by 's avatar
Browse files

Added check for vlan header 802.1q


git-svn-id: file:///home/svn/mapi/trunk@448 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent f2650e66
......@@ -35,6 +35,7 @@
#include <time.h>
#include "log.h"
#include "tracklib.h"
struct filters {
int protocol;
......@@ -54,6 +55,8 @@ struct list{
#define HASHTABLESIZE 101
#define STRING_NUM 15
int isDc(mapidflib_function_instance_t *instance, unsigned char *pkt, unsigned int len);
char *dc_strings[STRING_NUM]={"$MyNick","$Lock EXTENDEDPROTOCOL" ,"$Sending", "$Direction Download ","$Direction Upload ","$Supports", "$GetNickList|",
"$ValidateNick", "$ConnectToMe","$HubName","$Hello","$MyINFO $ALL","$GetINFO","$Search Hub:","$OpList"};
/* Backup Strings
......@@ -164,7 +167,9 @@ static int dc_process(mapidflib_function_instance_t *instance,
struct iphdr *iph = NULL;
struct tcphdr *tcph = NULL;
struct udphdr *udph = NULL;
struct vlan_802q_header *vlan_header;
unsigned int saddr, daddr;
struct in_addr source, dest;
......@@ -184,6 +189,12 @@ static int dc_process(mapidflib_function_instance_t *instance,
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_IP) {
return 0;
}
......@@ -212,7 +223,7 @@ static int dc_process(mapidflib_function_instance_t *instance,
p += tcph->doff * 4;
len -= tcph->doff * 4;
if((p - pkt) == pkt_head->caplen) {
if((unsigned int)(p - pkt) == pkt_head->caplen) {
return 0;
}
}
......@@ -226,7 +237,7 @@ static int dc_process(mapidflib_function_instance_t *instance,
p += sizeof(struct udphdr);
len -= sizeof(struct udphdr);
if((p - pkt) == pkt_head->caplen) {
if((unsigned int)(p - pkt) == pkt_head->caplen) {
return 0;
}
}
......
......@@ -29,6 +29,7 @@
#include "edonkey.h"
#include "log.h"
#include "tracklib.h"
struct filters {
int protocol;
......@@ -64,6 +65,7 @@ struct edonkey_header
};
char edonkey_string[] = "\x03\x02\x00\x70\x72\x01\x00\x00\x00";
int isEdonkeyString(mapidflib_function_instance_t *instance, unsigned char *pkt, unsigned int len);
static int edonkey_init(mapidflib_function_instance_t *instance, MAPI_UNUSED int fd)
{
......@@ -280,6 +282,8 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
struct timeval ts;
unsigned int len = pkt_head->caplen;
struct vlan_802q_header *vlan_header;
struct edonkey_header *edonkey_h;
unsigned int saddr, daddr;
......@@ -288,8 +292,7 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
uint16_t sp, dp;
unsigned int hashval = 0;
int i = 0;
p = pkt;
// lay the Ethernet header struct over the packet data
......@@ -302,6 +305,12 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
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_IP) {
return 0;
}
......@@ -333,7 +342,7 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
p += tcph->doff * 4;
len -= tcph->doff * 4;
if((p - pkt) == pkt_head->caplen) {
if((unsigned int)(p - pkt) == pkt_head->caplen) {
return 0;
}
......@@ -349,7 +358,7 @@ static int edonkey_process(mapidflib_function_instance_t *instance,
p += sizeof(struct udphdr);
len -= sizeof(struct udphdr);
if((p - pkt) == pkt_head->caplen) {
if((unsigned int)(p - pkt) == pkt_head->caplen) {
return 0;
}
}
......
......@@ -35,6 +35,7 @@
#include <time.h>
#include "log.h"
#include "tracklib.h"
struct filters {
int protocol;
......@@ -61,7 +62,7 @@ struct mapid_gnutella {
struct list **gnulist;
};
int isGnutella(mapidflib_function_instance_t *, unsigned char *, int );
int isGnutella(mapidflib_function_instance_t *, unsigned char *, unsigned int );
static int gnutella_init(mapidflib_function_instance_t *instance, MAPI_UNUSED int fd)
{
......@@ -83,7 +84,7 @@ static int gnutella_init(mapidflib_function_instance_t *instance, MAPI_UNUSED in
return 0;
}
int isGnutella(mapidflib_function_instance_t *instance, unsigned char *pkt, int len)
int isGnutella(mapidflib_function_instance_t *instance, unsigned char *pkt, unsigned int len)
{
int i=0;
......@@ -127,6 +128,8 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
struct tcphdr *tcph = NULL;
struct udphdr *udph = NULL;
struct vlan_802q_header *vlan_header;
unsigned int saddr, daddr;
struct in_addr source, dest;
......@@ -134,7 +137,8 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
unsigned int hashval = 0;
int i = 0;
p = pkt;
// lay the Ethernet header struct over the packet data
......@@ -146,6 +150,12 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
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_IP) {
return 0;
}
......@@ -173,7 +183,7 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
p += tcph->doff * 4;
if((p - pkt) == pkt_head->caplen) {
if((unsigned int)(p - pkt) == pkt_head->caplen) {
return 0;
}
len -= tcph->doff * 4;
......@@ -187,7 +197,7 @@ static int gnutella_process(mapidflib_function_instance_t *instance,
p += sizeof(struct udphdr);
if((p -pkt) == pkt_head->caplen) {
if((unsigned int)(p -pkt) == pkt_head->caplen) {
return 0;
}
len -= sizeof(struct udphdr);
......
......@@ -36,8 +36,7 @@
#include "log.h"
static int ipoverip_init(mapidflib_function_instance_t *instance, MAPI_UNUSED int fd)
{
static int ipoverip_init(mapidflib_function_instance_t *instance, MAPI_UNUSED int fd) {
return 0;
}
......@@ -83,10 +82,11 @@ static int ipoverip_process(mapidflib_function_instance_t *instance,
p += iph->ihl * 4;
len -= iph->ihl *4;
if(iph->protocol == 4) // TCP
{
// Found an IP-in-IP encaptulated packet
printf("found %d\n", iph->protocol);
return 1;
}
else
......@@ -98,8 +98,7 @@ static int ipoverip_process(mapidflib_function_instance_t *instance,
return 0;
}
static int ipoverip_cleanup(mapidflib_function_instance_t *instance)
{
static int ipoverip_cleanup(mapidflib_function_instance_t *instance) {
return 0;
}
......
......@@ -72,7 +72,7 @@ void renew_log_file(void)
void write_to_log(char *proto, char *string, int protocol, struct in_addr sip, uint16_t sp, struct in_addr dip, uint16_t dp, unsigned char *packet, unsigned int len)
{
static unsigned long long file_count = 0;
int i = 0;
unsigned int i = 0;
char *str = strdup(string);
char *p = NULL;
......
......@@ -35,6 +35,7 @@
#include <time.h>
#include "log.h"
#include "tracklib.h"
struct filters {
int protocol;
......@@ -58,12 +59,12 @@ char *torrent_strings[5]={"BitTorrent protocol","GET /scrape?info_hash=","GET /a
int torrent_lens[5]={20, 100, 100, 20, 20};
int isTorrent(mapidflib_function_instance_t *, unsigned char *, int );
int isTorrent(mapidflib_function_instance_t *, unsigned char *, unsigned int );
struct mapid_torrent {
int *shift[5];
int *skip[5];
int search_len[5];
unsigned int search_len[5];
struct list **torlist;
};
......@@ -88,7 +89,7 @@ static int torrent_init(mapidflib_function_instance_t *instance, MAPI_UNUSED int
return 0;
}
int isTorrent(mapidflib_function_instance_t *instance, unsigned char *pkt, int len)
int isTorrent(mapidflib_function_instance_t *instance, unsigned char *pkt, unsigned int len)
{
int i=0;
......@@ -134,7 +135,8 @@ static int torrent_process(mapidflib_function_instance_t *instance,
struct iphdr *iph = NULL;
struct tcphdr *tcph = NULL;
struct udphdr *udph = NULL;
struct vlan_802q_header *vlan_header;
unsigned int saddr, daddr;
struct in_addr source, dest;
......@@ -155,6 +157,12 @@ static int torrent_process(mapidflib_function_instance_t *instance,
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_IP) {
return 0;
}
......@@ -182,7 +190,7 @@ static int torrent_process(mapidflib_function_instance_t *instance,
p += tcph->doff * 4;
if((p - pkt) == pkt_head->caplen) {
if((unsigned int)(p - pkt) == pkt_head->caplen) {
return 0;
}
len -= tcph->doff;
......@@ -196,7 +204,7 @@ static int torrent_process(mapidflib_function_instance_t *instance,
p += sizeof(struct udphdr);
if((p - pkt) == pkt_head->caplen) {
if((unsigned int)(p - pkt) == pkt_head->caplen) {
return 0;
}
......
......@@ -35,6 +35,7 @@
#include <time.h>
#include "log.h"
#include "tracklib.h"
struct filters {
int protocol;
......@@ -101,6 +102,7 @@ static int trackftp_process(mapidflib_function_instance_t *instance,
unsigned int saddr, daddr;
struct in_addr source, dest;
struct vlan_802q_header *vlan_header;
uint16_t sp, dp;
......@@ -116,6 +118,12 @@ static int trackftp_process(mapidflib_function_instance_t *instance,
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 != ETHERTYPE_IP) {
return 0;
......
#ifndef __TRACKLIB_H__
#define __TRACKLIB_H__
#define ETHERTYPE_8021Q 0x8100
struct vlan_802q_header {
u_int16_t priority_cfi_vid;
u_int16_t ether_type;
};
#endif
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