Rework the network listening routine
This commit is contained in:
parent
2367bc23e8
commit
ce9b5fb364
@ -41,49 +41,60 @@
|
|||||||
#include "log_msg.h"
|
#include "log_msg.h"
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
process_packet_ethernet(fko_srv_options_t * opts, const unsigned char * packet,
|
||||||
|
unsigned short pkt_len, int caplen, int offset);
|
||||||
|
static void
|
||||||
|
process_packet_ipv4(fko_srv_options_t * opts, const unsigned char * packet,
|
||||||
|
int offset, unsigned char * fr_end);
|
||||||
|
static void
|
||||||
|
process_packet_ipv6(fko_srv_options_t * opts, const unsigned char * packet,
|
||||||
|
int offset, unsigned char * fr_end);
|
||||||
|
static void
|
||||||
|
process_packet_raw(fko_srv_options_t * opts, const unsigned char * packet);
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
process_packet(PROCESS_PKT_ARGS_TYPE *args, PACKET_HEADER_META,
|
process_packet(PROCESS_PKT_ARGS_TYPE *args, PACKET_HEADER_META,
|
||||||
const unsigned char *packet)
|
const unsigned char *packet)
|
||||||
{
|
{
|
||||||
struct ether_header *eth_p;
|
|
||||||
struct iphdr *iph_p;
|
|
||||||
struct tcphdr *tcph_p;
|
|
||||||
struct udphdr *udph_p;
|
|
||||||
struct icmphdr *icmph_p;
|
|
||||||
|
|
||||||
unsigned char *pkt_data;
|
|
||||||
unsigned short pkt_data_len;
|
|
||||||
unsigned char *pkt_end;
|
|
||||||
unsigned char *fr_end;
|
|
||||||
|
|
||||||
unsigned int ip_hdr_words;
|
|
||||||
|
|
||||||
unsigned char proto;
|
|
||||||
unsigned int src_ip;
|
|
||||||
unsigned int dst_ip;
|
|
||||||
|
|
||||||
unsigned short src_port = 0;
|
|
||||||
unsigned short dst_port = 0;
|
|
||||||
|
|
||||||
unsigned short eth_type;
|
|
||||||
|
|
||||||
fko_srv_options_t *opts = (fko_srv_options_t *)args;
|
fko_srv_options_t *opts = (fko_srv_options_t *)args;
|
||||||
|
|
||||||
int offset = opts->data_link_offset;
|
int offset = opts->data_link_offset;
|
||||||
|
|
||||||
|
if (offset != 0)
|
||||||
#if USE_LIBPCAP
|
#if USE_LIBPCAP
|
||||||
unsigned short pkt_len = packet_header->len;
|
process_packet_ethernet(opts, packet, packet_header->len,
|
||||||
|
packet_header->caplen, offset);
|
||||||
|
#else
|
||||||
|
process_packet_ethernet(opts, packet, pkt_len, pkt_len, offset);
|
||||||
|
#endif
|
||||||
|
else
|
||||||
|
process_packet_raw(opts, packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
process_packet_ethernet(fko_srv_options_t * opts, const unsigned char * packet,
|
||||||
|
unsigned short pkt_len, int caplen, int offset)
|
||||||
|
{
|
||||||
|
struct ether_header *eth_p;
|
||||||
|
|
||||||
|
unsigned char *fr_end;
|
||||||
|
|
||||||
|
unsigned short eth_type;
|
||||||
|
|
||||||
|
#if USE_LIBPCAP
|
||||||
/* Gotta have a complete ethernet header.
|
/* Gotta have a complete ethernet header.
|
||||||
*/
|
*/
|
||||||
if (packet_header->caplen < ETHER_HDR_LEN)
|
if (caplen < ETHER_HDR_LEN)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Determine packet end.
|
/* Determine packet end.
|
||||||
*/
|
*/
|
||||||
fr_end = (unsigned char *) packet + packet_header->caplen;
|
fr_end = (unsigned char *) packet + caplen;
|
||||||
#else
|
#else
|
||||||
/* This is coming from NFQ and we get the packet lentgh as an arg.
|
/* This is coming from NFQ and we get the packet length as an arg.
|
||||||
*/
|
*/
|
||||||
if (pkt_len < ETHER_HDR_LEN)
|
if (pkt_len < ETHER_HDR_LEN)
|
||||||
return;
|
return;
|
||||||
@ -127,6 +138,35 @@ process_packet(PROCESS_PKT_ARGS_TYPE *args, PACKET_HEADER_META,
|
|||||||
if (! ETHER_IS_VALID_LEN(pkt_len) )
|
if (! ETHER_IS_VALID_LEN(pkt_len) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (eth_type == ETHERTYPE_IP)
|
||||||
|
process_packet_ipv4(opts, packet, offset, fr_end);
|
||||||
|
else if (eth_type == ETHERTYPE_IPV6)
|
||||||
|
process_packet_ipv6(opts, packet, offset, fr_end);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
process_packet_ipv4(fko_srv_options_t * opts, const unsigned char * packet,
|
||||||
|
int offset, unsigned char * fr_end)
|
||||||
|
{
|
||||||
|
struct iphdr *iph_p;
|
||||||
|
struct tcphdr *tcph_p;
|
||||||
|
struct udphdr *udph_p;
|
||||||
|
struct icmphdr *icmph_p;
|
||||||
|
|
||||||
|
unsigned char *pkt_data;
|
||||||
|
unsigned short pkt_data_len;
|
||||||
|
unsigned char *pkt_end;
|
||||||
|
|
||||||
|
unsigned int ip_hdr_words;
|
||||||
|
|
||||||
|
unsigned char proto;
|
||||||
|
unsigned int src_ip;
|
||||||
|
unsigned int dst_ip;
|
||||||
|
|
||||||
|
unsigned short src_port = 0;
|
||||||
|
unsigned short dst_port = 0;
|
||||||
|
|
||||||
/* Pull the IP header.
|
/* Pull the IP header.
|
||||||
*/
|
*/
|
||||||
iph_p = (struct iphdr*)(packet + offset);
|
iph_p = (struct iphdr*)(packet + offset);
|
||||||
@ -236,4 +276,19 @@ process_packet(PROCESS_PKT_ARGS_TYPE *args, PACKET_HEADER_META,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
process_packet_ipv6(fko_srv_options_t * opts, const unsigned char * packet,
|
||||||
|
int offset, unsigned char * fr_end)
|
||||||
|
{
|
||||||
|
/* FIXME implement */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
process_packet_raw(fko_srv_options_t * opts, const unsigned char * packet)
|
||||||
|
{
|
||||||
|
/* FIXME implement */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***EOF***/
|
/***EOF***/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user