📄 snoop.h
字号:
/*************************************************************************** snoop.h - SNOOP HEADER ------------------- last updated : March 25 2003 copyright : (C) 2002 by Indradeep Biswas email : indradee@comp.nus.edu.sg ***************************************************************************/#ifndef SNOOP#define SNOOP//============ INCLUDE FILES - functions are imported from them ============#include <linux/module.h>#include <linux/skbuff.h> // Definition of the SOCKET BUFFER#include <linux/tcp.h> // Definition of the TCP packet#include <linux/ip.h> // Definition of the IP packet#include <linux/slab.h> // Malloc function#include <linux/time.h> // Timekeeping header file#include <linux/timer.h> // Used for Timer functions#include <linux/param.h> // Converts strings to other formats & V.V#include <linux/sched.h> // Used for schedulilng#include <asm/byteorder.h>#include <asm/semaphore.h>#include <net/tcp.h>#include <asm/io.h>//============ SNOOP CONTROL PARAMETERS ====================================#define SNOOP_MAXWINDOW 20 // Max # of packets to cache per conn#define SNOOP_MAXCONN 5 // Max # of connections to accept#define SNOOP_MAX_RXMIT 2 // Max # of local retransmissions#define SNOOP_CONN_TIMEOUT 40 // Max time in seconds before timeout #define SNOOP_RTO 30 // Default RTO set to 50 ms//============ SNOOP ERRORS - define types of errors =======================#define SNOOPE_SUCCESS 0 // Integer return for success.#define SNOOPE_NOTFOUND -1 // Item is not found#define SNOOPE_PKTFULL -2 // Packet buffer is full#define SNOOPE_CONFULL -3 // Connection buffer is full#define SNOOPE_NOMEM -4 // Out of memory - can't allocate#define SNOOPE_FORWARD -5 // Forward packet without processing#define SNOOPE_DROP -6 // Drop the packet from stack//============ SNOOP STATES - status bits ==================================#define SNOOP_ACTIVE 0x01 // connection active#define SNOOP_CLOSED 0x02 // connection closed#define SNOOP_FULL 0x04 // snoop cache full#define SNOOP_NOACK 0x08 // no ack seen yet#define SNOOP_DUPACK 0x16 // one dupack received ack seen yet//============ OTHER MISCELLANEOUS DEFINITINOS =============================#define IPPROTO_TCP 6 // Protocol value in IP header for TCP#define SNOOP_DEBUG 0 // If set, debug statements will be printed#define SNOOP_FH 1 // Segment from Fixed host#define SNOOP_MH 0 // Segment from Mobile host//============ BASIC TRAVERSAL FUNCTIONS ===================================#define NEXT(i) (i + 1) % SNOOP_MAXWINDOW#define PREV(i) (i == 0)? SNOOP_MAXWINDOW - 1 : i - 1//============ snoop_packet : sk_buff wrapper ==============================typedef struct snoop_packet { unsigned int conn_id; // stores the address of cs unsigned int seq; // sequence number pointer unsigned int size; // amount of actual TCP data unsigned long departure; // time when packet leaves - jiffies unsigned char num_rxmit; // number of local rexmits struct sk_buff *skb; // skbuff chain of data struct snoop_socket *sock; // snoop socket used to identify connection struct timer_list rexmit; // retransmission timeout timer spinlock_t lock; // mutual exclusion spinlock unsigned long irqflags; // for the spinlock} snoop_packet_t;//============ conn_state : control and maintain each connection ===========typedef struct conn_state{ unsigned char state; // state of connection unsigned int last_seq; // first byte of last packet buffered unsigned int last_ack; // last byte recd. by mh for sure unsigned char tail; // next pkt goes here unsigned char head; // first unack'd pkt unsigned long rto; // retransmission timeout struct snoop_socket *sock; // snoop socket struct timer_list timeout; // times out the connection when idle. struct semaphore mutex; snoop_packet_t *pkts[SNOOP_MAXWINDOW];// circular pointer array} snoop_cs_t;//============ controller : control structure for snoop module =============typedef struct controller { unsigned short num_connections; // number of active connections snoop_cs_t *cstate[SNOOP_MAXCONN]; // array of per-connection state} snoop_control_t;//============ snoop_socket : a tcp socket for snoop =======================struct snoop_socket { unsigned int daddr; // destination ip address unsigned int saddr; // source ip address unsigned short dest; // destination port number unsigned short source; // source port number};//============ snoop_flags : keeps the flags temporarily ===================struct snoop_flags { __u8 syn:1, // syn flag for connection start ack:1, // ack flag for acknowledgement fin:1, // fin flag for finishing off a connection rst:1, // rst flag for resetting connection others:4; // other flags can be accomodated here};//============ snoop_buffer : a wrapper for skb ============================struct snoop_buffer { struct sk_buff *skb; // pointer to the actual sk_buff struct snoop_socket *sock; // socket for the packet above struct snoop_flags *flags; // flags for the packet above unsigned int seq; // sequence number for the packet unsigned int ack_seq; // acknowledgement number unsigned int size; // size of the above packet};#endif//============ MISCELLANEOUS DEFINITIONS ===================================int (* snoop_ip_forward)(struct sk_buff *);//forward hookint (* snoop_ip_forward_finish)(struct sk_buff *); // kernel symbolsnoop_control_t snoop_control; // SNOOP module control structure//============ snoop.c : FUNCTION LIST =====================================void * snoop_malloc (int);int snoop_init_control();int snoop_init_conn(struct snoop_buffer *);int snoop_data(struct snoop_buffer *, unsigned int);int snoop_insert(unsigned int, struct snoop_buffer *);int snoop_save_packet (snoop_packet_t *, struct snoop_buffer *, unsigned int);int snoop_forward (struct sk_buff *, snoop_packet_t *);int snoop_ack(struct snoop_buffer *, unsigned int);void snoop_clean_buff (unsigned int, unsigned int);void snoop_free_packet (snoop_packet_t *);void snoop_clean_conn(unsigned int);void snoop_clean_conrol();int snoop_getconn(struct snoop_buffer *, char *);void snoop_error (char, char[]);int snoop_main(struct sk_buff *);void snoop_free_skb (struct sk_buff * free_skb);void snoop_conn_timeout (unsigned long);void snoop_packet_retransmit(unsigned long);void snoop_rto_calc (snoop_cs_t *, unsigned long );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -