Browse Source

fixed indentation in all relay station code files

cecylia 6 years ago
parent
commit
17dc50801a

File diff suppressed because it is too large
+ 485 - 485
relay_station/crypto.c


+ 8 - 8
relay_station/crypto.h

@@ -32,7 +32,7 @@
 #include "ptwist.h"
 
 #define n2s(c,s)        ((s=(((unsigned int)(c[0]))<< 8)| \
-							(((unsigned int)(c[1]))    )),c+=2)
+            (((unsigned int)(c[1]))    )),c+=2)
 
 
 /* Curves */
@@ -55,11 +55,11 @@ int extract_server_random(flow *f, uint8_t *hs);
 int compute_master_secret(flow *f);
 
 int PRF(flow *f, uint8_t *secret, int32_t secret_len,
-		uint8_t *seed1, int32_t seed1_len,
-		uint8_t *seed2, int32_t seed2_len,
-		uint8_t *seed3, int32_t seed3_len,
-		uint8_t *seed4, int32_t seed4_len,
-		uint8_t *output, int32_t output_len);
+        uint8_t *seed1, int32_t seed1_len,
+        uint8_t *seed2, int32_t seed2_len,
+        uint8_t *seed3, int32_t seed3_len,
+        uint8_t *seed4, int32_t seed4_len,
+        uint8_t *output, int32_t output_len);
 
 int mark_finished_hash(flow *f, uint8_t *hs);
 int init_ciphers(flow *f);
@@ -68,8 +68,8 @@ int super_encrypt(client *c, uint8_t *data, uint32_t len);
 void check_handshake(struct packet_info *info);
 
 int check_tag(byte key[16], const byte privkey[PTWIST_BYTES],
-	const byte tag[PTWIST_TAG_BYTES], const byte *context,
-	size_t context_len);
+        const byte tag[PTWIST_TAG_BYTES], const byte *context,
+        size_t context_len);
 #define PRE_MASTER_MAX_LEN BUFSIZ
 
 #define SLITHEEN_KEYGEN_CONST "SLITHEEN_KEYGEN"

+ 26 - 26
relay_station/cryptothread.c

@@ -39,45 +39,45 @@ static long *lock_count;
 
 void init_crypto_locks(void){
 
-	crypto_locks = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
-	if(!crypto_locks)
-		exit(1);
-	lock_count = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long));
-	if(!lock_count)
-		exit(1);
-	for (int i = 0; i < CRYPTO_num_locks(); i++) {
-		lock_count[i] = 0;
-		pthread_mutex_init(&(crypto_locks[i]), NULL);
-	}
+    crypto_locks = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
+    if(!crypto_locks)
+        exit(1);
+    lock_count = OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long));
+    if(!lock_count)
+        exit(1);
+    for (int i = 0; i < CRYPTO_num_locks(); i++) {
+        lock_count[i] = 0;
+        pthread_mutex_init(&(crypto_locks[i]), NULL);
+    }
 
-	CRYPTO_THREADID_set_callback(pthreads_thread_id);
-	CRYPTO_set_locking_callback(pthreads_locking_callback);
+    CRYPTO_THREADID_set_callback(pthreads_thread_id);
+    CRYPTO_set_locking_callback(pthreads_locking_callback);
 }
 
 void crypto_locks_cleanup(void){
-	int i;
+    int i;
 
-	CRYPTO_set_locking_callback(NULL);
-	for (i = 0; i < CRYPTO_num_locks(); i++) {
-		pthread_mutex_destroy(&(crypto_locks[i]));
-	}
-	OPENSSL_free(crypto_locks);
-	OPENSSL_free(lock_count);
+    CRYPTO_set_locking_callback(NULL);
+    for (i = 0; i < CRYPTO_num_locks(); i++) {
+        pthread_mutex_destroy(&(crypto_locks[i]));
+    }
+    OPENSSL_free(crypto_locks);
+    OPENSSL_free(lock_count);
 
 }
 
 /** If the mode is CRYPTO_LOCK, the lock indicated by type will be acquired, otherwise it will be released */
 void pthreads_locking_callback(int mode, int type, const char *file, int line){
 
-	if(mode & CRYPTO_LOCK){
-		pthread_mutex_lock(&(crypto_locks[type]));
-		lock_count[type]++;
-	} else {
-		pthread_mutex_unlock(&(crypto_locks[type]));
-	}
+    if(mode & CRYPTO_LOCK){
+        pthread_mutex_lock(&(crypto_locks[type]));
+        lock_count[type]++;
+    } else {
+        pthread_mutex_unlock(&(crypto_locks[type]));
+    }
 }
 
 void pthreads_thread_id(CRYPTO_THREADID *tid){
-	CRYPTO_THREADID_set_numeric(tid, (unsigned long)pthread_self());
+    CRYPTO_THREADID_set_numeric(tid, (unsigned long)pthread_self());
 }
 

File diff suppressed because it is too large
+ 502 - 502
relay_station/flow.c


+ 114 - 114
relay_station/flow.h

@@ -58,44 +58,44 @@ struct client_st;
 typedef struct client_st client;
 
 typedef struct stream_st {
-	uint16_t stream_id;
-	int32_t pipefd;
-	struct stream_st *next;
+    uint16_t stream_id;
+    int32_t pipefd;
+    struct stream_st *next;
 } stream;
 
 typedef struct stream_table_st {
-	stream *first;
+    stream *first;
 } stream_table;
 
 typedef struct packet_st{
-	uint32_t seq_num;
-	uint16_t len;
-	uint8_t *data;
-	uint32_t expiration;
-	struct packet_st *next;
+    uint32_t seq_num;
+    uint16_t len;
+    uint8_t *data;
+    uint32_t expiration;
+    struct packet_st *next;
 } packet;
 
 typedef struct packet_chain_st {
-	packet *first_packet;
-	uint32_t expected_seq_num;
-	uint32_t record_len;
-	uint32_t remaining_record_len;
+    packet *first_packet;
+    uint32_t expected_seq_num;
+    uint32_t record_len;
+    uint32_t remaining_record_len;
 } packet_chain;
 
 typedef struct queue_block_st{
-	int32_t len;
-	int32_t offset;
-	uint8_t *data;
-	struct queue_block_st *next;
-	uint16_t stream_id;
+    int32_t len;
+    int32_t offset;
+    uint8_t *data;
+    struct queue_block_st *next;
+    uint16_t stream_id;
 } queue_block;
 
 typedef struct data_queue_st {
-	queue_block *first_block;
+    queue_block *first_block;
 } data_queue;
 
 typedef struct app_data_queue_st {
-	packet *first_packet;
+    packet *first_packet;
 } app_data_queue;
 
 typedef struct frame_st {
@@ -111,121 +111,121 @@ typedef struct frame_queue_st {
 } frame_queue;
 
 typedef struct session_st {
-	uint8_t session_id_len;
-	uint8_t session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
-	struct session_st *next;
-	uint8_t master_secret[SSL3_MASTER_SECRET_SIZE];
-	uint8_t client_random[SSL3_RANDOM_SIZE];
-	uint8_t server_random[SSL3_RANDOM_SIZE];
-	uint32_t session_ticket_len;
-	uint8_t *session_ticket;
+    uint8_t session_id_len;
+    uint8_t session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
+    struct session_st *next;
+    uint8_t master_secret[SSL3_MASTER_SECRET_SIZE];
+    uint8_t client_random[SSL3_RANDOM_SIZE];
+    uint8_t server_random[SSL3_RANDOM_SIZE];
+    uint32_t session_ticket_len;
+    uint8_t *session_ticket;
 } session;
 
 typedef struct session_cache_st {
-	session *first_session;
-	uint32_t length;
+    session *first_session;
+    uint32_t length;
 } session_cache;
 
 typedef struct flow_st {
-	sem_t flow_lock;
+    sem_t flow_lock;
 
-	uint32_t ref_ctr;
-	uint8_t removed;
+    uint32_t ref_ctr;
+    uint8_t removed;
 
-	struct in_addr src_ip, dst_ip; /* Source (client) and Destination (server) addresses */
-	uint16_t src_port, dst_port;	/* Source and Destination ports */
+    struct in_addr src_ip, dst_ip; /* Source (client) and Destination (server) addresses */
+    uint16_t src_port, dst_port;	/* Source and Destination ports */
 
-	uint32_t upstream_seq_num;		/* sequence number */
-	uint32_t downstream_seq_num;		/* sequence number */
+    uint32_t upstream_seq_num;		/* sequence number */
+    uint32_t downstream_seq_num;		/* sequence number */
 
-	app_data_queue *upstream_app_data;	/* Saved application-layer data for packet retransmits */
-	app_data_queue *downstream_app_data;
+    app_data_queue *upstream_app_data;	/* Saved application-layer data for packet retransmits */
+    app_data_queue *downstream_app_data;
 
     frame_queue *us_frame_queue; /*Held misordered Ethernet frames to be processed and written out later */
     frame_queue *ds_frame_queue; /*Held misordered Ethernet frames to be processed and written out later */
 
-	byte key[16];		/* negotiated key */
-	int state;		/* TLS handshake state */
-	int in_encrypted;		/* indicates whether incoming flow is encrypted */
-	int out_encrypted;		/* indicates whether outgoing flow is encrypted */
-	int application; /* indicates handshake is complete */
-	int stall; /* indicates the Finished message is expected and relay station should stall */
-	int resume_session;
-	stream_table *streams; //TODO delete (reference client)
-	data_queue *downstream_queue; //TODO: delete (reference client)
-	client *client_ptr;
-
-	packet_chain *ds_packet_chain;
-	packet_chain *us_packet_chain;
-        queue *ds_hs_queue;
-        queue *us_hs_queue;
-	sem_t packet_chain_lock;
-
-	queue_block *upstream_queue;
-	uint32_t upstream_remaining;
-	DH *dh;
-	EC_KEY *ecdh;
-        EVP_PKEY *srvr_key;
-	sem_t upstream_queue_lock;
-
-	const EVP_CIPHER *cipher;
-	const EVP_MD *message_digest;
-	uint8_t keyex_alg;
-        uint8_t extended_master_secret;
-	uint8_t handshake_hash[EVP_MAX_MD_SIZE];
-	EVP_CIPHER_CTX *clnt_read_ctx;
-	EVP_CIPHER_CTX *clnt_write_ctx;
-	EVP_CIPHER_CTX *srvr_read_ctx;
-	EVP_CIPHER_CTX *srvr_write_ctx;
-	EVP_MD_CTX *read_mac_ctx;
-	EVP_MD_CTX *write_mac_ctx;
-        EVP_MD_CTX *hs_md_ctx;
-
-        GCM128_CONTEXT *gcm_ctx_out;
-        uint8_t *gcm_ctx_iv;
-        int32_t gcm_ctx_ivlen;
-        AES_KEY *gcm_ctx_key;
-
-	uint8_t client_random[SSL3_RANDOM_SIZE];
-	uint8_t server_random[SSL3_RANDOM_SIZE];
-	uint8_t master_secret[SSL3_MASTER_SECRET_SIZE];
-
-	session *current_session;
-
-	uint8_t read_seq[8];
-	uint8_t write_seq[8];
-
-	//for downstream processing
-	uint32_t remaining_record_len;
-	uint8_t httpstate;
-	uint32_t remaining_response_len;
-	uint8_t replace_response;
-
-	uint8_t *outbox;
-	int32_t outbox_len;
-	int32_t outbox_offset;
-
-	uint8_t *partial_record_header;
-	uint8_t partial_record_header_len;
-
-        uint8_t *partial_record;
-        uint8_t *partial_record_dec;
-        uint32_t partial_record_len;
-        uint32_t partial_record_total_len;
-
-	//locking
-	//pthread_mutex_t flow_lock = PTHREAD_MUTEX_INITIALIZER;
+    byte key[16];		/* negotiated key */
+    int state;		/* TLS handshake state */
+    int in_encrypted;		/* indicates whether incoming flow is encrypted */
+    int out_encrypted;		/* indicates whether outgoing flow is encrypted */
+    int application; /* indicates handshake is complete */
+    int stall; /* indicates the Finished message is expected and relay station should stall */
+    int resume_session;
+    stream_table *streams; //TODO delete (reference client)
+    data_queue *downstream_queue; //TODO: delete (reference client)
+    client *client_ptr;
+
+    packet_chain *ds_packet_chain;
+    packet_chain *us_packet_chain;
+    queue *ds_hs_queue;
+    queue *us_hs_queue;
+    sem_t packet_chain_lock;
+
+    queue_block *upstream_queue;
+    uint32_t upstream_remaining;
+    DH *dh;
+    EC_KEY *ecdh;
+    EVP_PKEY *srvr_key;
+    sem_t upstream_queue_lock;
+
+    const EVP_CIPHER *cipher;
+    const EVP_MD *message_digest;
+    uint8_t keyex_alg;
+    uint8_t extended_master_secret;
+    uint8_t handshake_hash[EVP_MAX_MD_SIZE];
+    EVP_CIPHER_CTX *clnt_read_ctx;
+    EVP_CIPHER_CTX *clnt_write_ctx;
+    EVP_CIPHER_CTX *srvr_read_ctx;
+    EVP_CIPHER_CTX *srvr_write_ctx;
+    EVP_MD_CTX *read_mac_ctx;
+    EVP_MD_CTX *write_mac_ctx;
+    EVP_MD_CTX *hs_md_ctx;
+
+    GCM128_CONTEXT *gcm_ctx_out;
+    uint8_t *gcm_ctx_iv;
+    int32_t gcm_ctx_ivlen;
+    AES_KEY *gcm_ctx_key;
+
+    uint8_t client_random[SSL3_RANDOM_SIZE];
+    uint8_t server_random[SSL3_RANDOM_SIZE];
+    uint8_t master_secret[SSL3_MASTER_SECRET_SIZE];
+
+    session *current_session;
+
+    uint8_t read_seq[8];
+    uint8_t write_seq[8];
+
+    //for downstream processing
+    uint32_t remaining_record_len;
+    uint8_t httpstate;
+    uint32_t remaining_response_len;
+    uint8_t replace_response;
+
+    uint8_t *outbox;
+    int32_t outbox_len;
+    int32_t outbox_offset;
+
+    uint8_t *partial_record_header;
+    uint8_t partial_record_header_len;
+
+    uint8_t *partial_record;
+    uint8_t *partial_record_dec;
+    uint32_t partial_record_len;
+    uint32_t partial_record_total_len;
+
+    //locking
+    //pthread_mutex_t flow_lock = PTHREAD_MUTEX_INITIALIZER;
 
 } flow;
 
 typedef struct flow_entry_st {
-	flow *f;
-	struct flow_entry_st *next;
+    flow *f;
+    struct flow_entry_st *next;
 } flow_entry;
 
 typedef struct flow_table_st {
-	flow_entry *first_entry;
-	int len;
+    flow_entry *first_entry;
+    int len;
 } flow_table;
 
 

+ 1 - 1
relay_station/ptwist.h

@@ -59,6 +59,6 @@ typedef unsigned char byte;
  * matter.)  Multiply that point by seckey and set out to the
  * x-coordinate of the result. */
 void ptwist_pointmul(byte out[PTWIST_BYTES], const byte x[PTWIST_BYTES],
-	const byte seckey[PTWIST_BYTES]);
+        const byte seckey[PTWIST_BYTES]);
 
 #endif

File diff suppressed because it is too large
+ 631 - 631
relay_station/relay.c


+ 26 - 26
relay_station/relay.h

@@ -32,46 +32,46 @@
 #include <stdint.h>
 
 struct proxy_thread_data {
-	uint8_t *initial_data;
-	uint16_t initial_len;
-	uint16_t stream_id;
-	int32_t pipefd;
-	stream_table *streams;
-	data_queue *downstream_queue;
-	client *client;
+    uint8_t *initial_data;
+    uint16_t initial_len;
+    uint16_t stream_id;
+    int32_t pipefd;
+    stream_table *streams;
+    data_queue *downstream_queue;
+    client *client;
 };
 
 typedef struct client_st {
-	uint8_t slitheen_id[SLITHEEN_ID_LEN];
-	stream_table *streams;
-	data_queue *downstream_queue;
-	sem_t queue_lock;
-	uint16_t encryption_counter;
-	struct client_st *next;
-	uint8_t *header_key;
-	uint8_t *body_key;
-	//uint8_t *mac_key
-	//EVP_CIPHER_CTX *header_ctx;
-	//EVP_CIPHER_CTX *body_ctx;
-	EVP_MD_CTX *mac_ctx;
+    uint8_t slitheen_id[SLITHEEN_ID_LEN];
+    stream_table *streams;
+    data_queue *downstream_queue;
+    sem_t queue_lock;
+    uint16_t encryption_counter;
+    struct client_st *next;
+    uint8_t *header_key;
+    uint8_t *body_key;
+    //uint8_t *mac_key
+    //EVP_CIPHER_CTX *header_ctx;
+    //EVP_CIPHER_CTX *body_ctx;
+    EVP_MD_CTX *mac_ctx;
 } client;
 
 typedef struct client_table_st {
-	client *first;
+    client *first;
 } client_table;
 
 extern client_table *clients;
 
 struct socks_req {
-	uint8_t version;
-	uint8_t cmd;
-	uint8_t rsvd;
-	uint8_t addr_type;
+    uint8_t version;
+    uint8_t cmd;
+    uint8_t rsvd;
+    uint8_t addr_type;
 };
 
 struct __attribute__((__packed__)) sl_up_hdr {
-	uint16_t stream_id;
-	uint16_t len;
+    uint16_t stream_id;
+    uint16_t len;
 };
 
 int replace_packet(flow *f, struct packet_info *info);

+ 150 - 150
relay_station/slitheen-proxy.c

@@ -50,112 +50,112 @@ void update_window_expiration(flow *f, struct packet_info *info);
 void retransmit(flow *f, struct packet_info *info, uint32_t data_to_fill);
 
 void usage(void){
-	printf("Usage: slitheen-proxy [internal network interface] [NAT interface]\n");
+    printf("Usage: slitheen-proxy [internal network interface] [NAT interface]\n");
 }
 
 int main(int argc, char *argv[]){
-	pthread_t t1, t2;
+    pthread_t t1, t2;
 
-	char *dev1 = NULL; /* Device that leads to the internal network */
-	char *dev2 = NULL; /* Device that leads out to the world */
+    char *dev1 = NULL; /* Device that leads to the internal network */
+    char *dev2 = NULL; /* Device that leads out to the world */
 
-	struct sniff_args outbound;
-	struct sniff_args inbound;
+    struct sniff_args outbound;
+    struct sniff_args inbound;
 
-	if (argc != 3) { 
-		usage();
-		return(2);
-	}
-	dev1 = argv[1];
-	dev2 = argv[2];
+    if (argc != 3) { 
+        usage();
+        return(2);
+    }
+    dev1 = argv[1];
+    dev2 = argv[2];
 
-	if(init_tables()){
-		exit(1);
-	}
-	if(init_session_cache()){
-		exit(1);
-	}
-	init_crypto_locks();
+    if(init_tables()){
+        exit(1);
+    }
+    if(init_session_cache()){
+        exit(1);
+    }
+    init_crypto_locks();
 
-	/* Create threads */
-	outbound.readdev = dev1;
-	outbound.writedev = dev2;
+    /* Create threads */
+    outbound.readdev = dev1;
+    outbound.writedev = dev2;
 
-	inbound.readdev = dev2;
-	inbound.writedev = dev1;
+    inbound.readdev = dev2;
+    inbound.writedev = dev1;
 
-	pthread_create(&t1, NULL, sniff_packets, (void *) &outbound);
-	pthread_create(&t2, NULL, sniff_packets, (void *) &inbound);
+    pthread_create(&t1, NULL, sniff_packets, (void *) &outbound);
+    pthread_create(&t2, NULL, sniff_packets, (void *) &inbound);
 
-	pthread_join(t1, NULL);
-	pthread_join(t2, NULL);
+    pthread_join(t1, NULL);
+    pthread_join(t2, NULL);
 
-	pthread_exit(NULL);
+    pthread_exit(NULL);
 
-	crypto_locks_cleanup();
+    crypto_locks_cleanup();
 
-	return(0);
+    return(0);
 }
 
 void *sniff_packets(void *args){
-	pcap_t *rd_handle;
-	pcap_t *wr_handle;
-	char rd_errbuf[BUFSIZ];
-	char wr_errbuf[BUFSIZ];
-        uint8_t MAC[ETHER_ADDR_LEN];
-	bpf_u_int32 mask;
-	bpf_u_int32 net;
-
-	char *readdev, *writedev;
-	struct sniff_args *arg_st = (struct sniff_args *) args;
-	readdev = arg_st->readdev;
-	writedev = arg_st->writedev;
-
-        //Find MAC address of each interface
-        struct ifreq ifr;
-        int s = socket(AF_INET, SOCK_DGRAM, 0);
-        strcpy(ifr.ifr_name, writedev);
-        ioctl(s, SIOCGIFHWADDR, &ifr);
-        memcpy(MAC, ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
-        close(s);
-
-	if (pcap_lookupnet(readdev, &net, &mask, rd_errbuf) == -1){
-		fprintf(stderr, "Can't get netmask for device %s\n", readdev);
-		exit(2);
-	}
-
-	rd_handle = pcap_open_live(readdev, BUFSIZ, 0, 0, rd_errbuf);
-	if (rd_handle == NULL){
-		fprintf(stderr, "Couldn't open device %s: %s\n", readdev, rd_errbuf);
-	}
-
-	if(pcap_datalink(rd_handle) != DLT_EN10MB) {
-		fprintf(stderr, "Device %s does not provide Ethernet headers - not supported\n", readdev);
-		exit(2);
-	}
-
-	if(pcap_setdirection(rd_handle, PCAP_D_IN)){
-		fprintf(stderr, "Platform does not support write direction. Update filters with MAC address\n");
-		exit(2);
-	}
-
-	wr_handle = pcap_open_live(writedev, BUFSIZ, 0, 0, wr_errbuf);
-	if (wr_handle == NULL){
-		fprintf(stderr, "Couldn't open device %s: %s\n", writedev, wr_errbuf);
-	}
-
-        struct inject_args iargs;
-        iargs.mac_addr = MAC;
-        iargs.write_dev = wr_handle;
-
-
-	/*callback function*/
-	pcap_loop(rd_handle, -1, got_packet, (unsigned char *) &iargs);
-
-	/*Sniff a packet*/
-	pcap_close(rd_handle);
-
-	return NULL;
+    pcap_t *rd_handle;
+    pcap_t *wr_handle;
+    char rd_errbuf[BUFSIZ];
+    char wr_errbuf[BUFSIZ];
+    uint8_t MAC[ETHER_ADDR_LEN];
+    bpf_u_int32 mask;
+    bpf_u_int32 net;
+
+    char *readdev, *writedev;
+    struct sniff_args *arg_st = (struct sniff_args *) args;
+    readdev = arg_st->readdev;
+    writedev = arg_st->writedev;
+
+    //Find MAC address of each interface
+    struct ifreq ifr;
+    int s = socket(AF_INET, SOCK_DGRAM, 0);
+    strcpy(ifr.ifr_name, writedev);
+    ioctl(s, SIOCGIFHWADDR, &ifr);
+    memcpy(MAC, ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
+    close(s);
+
+    if (pcap_lookupnet(readdev, &net, &mask, rd_errbuf) == -1){
+        fprintf(stderr, "Can't get netmask for device %s\n", readdev);
+        exit(2);
+    }
+
+    rd_handle = pcap_open_live(readdev, BUFSIZ, 0, 0, rd_errbuf);
+    if (rd_handle == NULL){
+        fprintf(stderr, "Couldn't open device %s: %s\n", readdev, rd_errbuf);
+    }
+
+    if(pcap_datalink(rd_handle) != DLT_EN10MB) {
+        fprintf(stderr, "Device %s does not provide Ethernet headers - not supported\n", readdev);
+        exit(2);
+    }
+
+    if(pcap_setdirection(rd_handle, PCAP_D_IN)){
+        fprintf(stderr, "Platform does not support write direction. Update filters with MAC address\n");
+        exit(2);
+    }
+
+    wr_handle = pcap_open_live(writedev, BUFSIZ, 0, 0, wr_errbuf);
+    if (wr_handle == NULL){
+        fprintf(stderr, "Couldn't open device %s: %s\n", writedev, wr_errbuf);
+    }
+
+    struct inject_args iargs;
+    iargs.mac_addr = MAC;
+    iargs.write_dev = wr_handle;
+
+
+    /*callback function*/
+    pcap_loop(rd_handle, -1, got_packet, (unsigned char *) &iargs);
+
+    /*Sniff a packet*/
+    pcap_close(rd_handle);
+
+    return NULL;
 }
 
 
@@ -226,7 +226,7 @@ void process_packet(struct inject_args *iargs, const struct pcap_pkthdr *header,
     /* Now if flow is in table, update state */
     flow *observed;
     if((observed = check_flow(info)) != NULL){
-    
+
 #ifdef DEBUG
         /*Check sequence number and replay application data if necessary*/
         fprintf(stdout,"Flow: %x:%d > %x:%d (%s)\n", info->ip_hdr->src.s_addr, ntohs(info->tcp_hdr->src_port), info->ip_hdr->dst.s_addr, ntohs(info->tcp_hdr->dst_port), (info->ip_hdr->src.s_addr != observed->src_ip.s_addr)? "incoming":"outgoing");
@@ -336,7 +336,7 @@ void process_packet(struct inject_args *iargs, const struct pcap_pkthdr *header,
             /* add packet to application data queue */
             save_packet(observed, info);
         }
-        
+
 
         /*process and release held frames with current sequence numbers*/
         frame_queue *queue = (incoming) ? observed->ds_frame_queue : observed->us_frame_queue;
@@ -450,7 +450,7 @@ void save_packet(flow *f, struct packet_info *info){
 #endif
                 }
             }
-                
+
             saved_data = saved_data->next;
 
         }
@@ -591,7 +591,7 @@ void retransmit(flow *f, struct packet_info *info, uint32_t data_to_fill){
             }
         } else { //seq_num > saved_data->seq_num
             uint32_t offset = seq_num - saved_data->seq_num;
-            
+
             if(offset > saved_data->len){
                 saved_data = saved_data->next;
                 offset -= saved_data->len;
@@ -621,70 +621,70 @@ void retransmit(flow *f, struct packet_info *info, uint32_t data_to_fill){
  */
 void extract_packet_headers(uint8_t *packet, struct packet_info *info){
 
-	/* First fill in IP header */
-	uint8_t *p = packet;
-	p += ETHER_HEADER_LEN; //skip ethernet header
-	info->ip_hdr = (struct ip_header*) p;
-	info->size_ip_hdr = IP_HEADER_LEN(info->ip_hdr);
-	
-	/* Verify this is an IP packet */
-	if( (info->ip_hdr->versionihl >>4) != 4){
-		info->ip_hdr = NULL;
-		info->size_ip_hdr = 0;
-		info->tcp_hdr = NULL;
-		info->size_tcp_hdr = 0;
-		info->record_hdr = NULL;
-		return;
-	}
-
-	/* If this is a TCP segment, fill in TCP header */
-	if (info->ip_hdr->proto == IPPROTO_TCP){
-		p += info->size_ip_hdr;	//skip IP header
-
-		info->tcp_hdr = (struct tcp_header*) p;
-		info->size_tcp_hdr = TCP_HEADER_LEN(info->tcp_hdr);
-		p += info->size_tcp_hdr;
-	} else {
-		info->tcp_hdr = NULL;
-		info->size_tcp_hdr = 0;
-		info->record_hdr = NULL;
-		return;
-	}
-
-
-	/* If the application data contains a TLS record, fill in hdr */
-	info->app_data_len = htons(info->ip_hdr->len) - (info->size_ip_hdr + info->size_tcp_hdr);
-	if(info->app_data_len > 0){
-		info->app_data = p;
-		info->record_hdr = (struct tls_header*) p;
-		
-		//check to see if this is a valid record
-		if((info->record_hdr->type < 0x14) || (info->record_hdr->type > 0x18)){
-			info->record_hdr = NULL;
-		}
-
-	} else {
-		info->record_hdr = NULL;
-		info->app_data = NULL;
-	}
-
-	return;
+    /* First fill in IP header */
+    uint8_t *p = packet;
+    p += ETHER_HEADER_LEN; //skip ethernet header
+    info->ip_hdr = (struct ip_header*) p;
+    info->size_ip_hdr = IP_HEADER_LEN(info->ip_hdr);
+
+    /* Verify this is an IP packet */
+    if( (info->ip_hdr->versionihl >>4) != 4){
+        info->ip_hdr = NULL;
+        info->size_ip_hdr = 0;
+        info->tcp_hdr = NULL;
+        info->size_tcp_hdr = 0;
+        info->record_hdr = NULL;
+        return;
+    }
+
+    /* If this is a TCP segment, fill in TCP header */
+    if (info->ip_hdr->proto == IPPROTO_TCP){
+        p += info->size_ip_hdr;	//skip IP header
+
+        info->tcp_hdr = (struct tcp_header*) p;
+        info->size_tcp_hdr = TCP_HEADER_LEN(info->tcp_hdr);
+        p += info->size_tcp_hdr;
+    } else {
+        info->tcp_hdr = NULL;
+        info->size_tcp_hdr = 0;
+        info->record_hdr = NULL;
+        return;
+    }
+
+
+    /* If the application data contains a TLS record, fill in hdr */
+    info->app_data_len = htons(info->ip_hdr->len) - (info->size_ip_hdr + info->size_tcp_hdr);
+    if(info->app_data_len > 0){
+        info->app_data = p;
+        info->record_hdr = (struct tls_header*) p;
+
+        //check to see if this is a valid record
+        if((info->record_hdr->type < 0x14) || (info->record_hdr->type > 0x18)){
+            info->record_hdr = NULL;
+        }
+
+    } else {
+        info->record_hdr = NULL;
+        info->app_data = NULL;
+    }
+
+    return;
 
 }
 
 /** Copies a packet_info structure and returns a pointer to the duplicate.
- */
+*/
 struct packet_info *copy_packet_info(struct packet_info *src_info){
-	struct packet_info *dst_info = emalloc(sizeof(struct packet_info));
+    struct packet_info *dst_info = emalloc(sizeof(struct packet_info));
 
-	dst_info->ip_hdr = src_info->ip_hdr;
-	dst_info->tcp_hdr = src_info->tcp_hdr;
+    dst_info->ip_hdr = src_info->ip_hdr;
+    dst_info->tcp_hdr = src_info->tcp_hdr;
 
-	dst_info->size_tcp_hdr = src_info->size_tcp_hdr;
-	dst_info->size_ip_hdr = src_info->size_ip_hdr;
+    dst_info->size_tcp_hdr = src_info->size_tcp_hdr;
+    dst_info->size_ip_hdr = src_info->size_ip_hdr;
 
-	dst_info->app_data = src_info->app_data;
-	dst_info->app_data_len = src_info->app_data_len;
+    dst_info->app_data = src_info->app_data;
+    dst_info->app_data_len = src_info->app_data_len;
 
-	return dst_info;
+    return dst_info;
 }

+ 43 - 43
relay_station/slitheen.h

@@ -37,46 +37,46 @@
 
 /* Definitions for parsing packet data */
 struct ip_header {
-	u_char versionihl;		/* Version >> 4 | IHL & 0x0f */
-	u_char dscpecn;		/* DSCP >> 2 | ECN  & 0x03 */
-	u_short len;		/* Total Length */
-	u_short id;		/* Identification */
-	u_short flagsoff;		/* Flags >> 13 | Fragment Offset & 0x1fff */
+    u_char versionihl;		/* Version >> 4 | IHL & 0x0f */
+    u_char dscpecn;		/* DSCP >> 2 | ECN  & 0x03 */
+    u_short len;		/* Total Length */
+    u_short id;		/* Identification */
+    u_short flagsoff;		/* Flags >> 13 | Fragment Offset & 0x1fff */
 #define RF 0x8000		/* Reserved; must be zero */
 #define DF 0x4000		/* Dont Fragment */
 #define MF 0x2000		/* More Fragments */
-	u_char ttl;		/* Time To Live */
-	u_char proto;		/* Protocol */
-	u_short chksum;		/* Header Checksum */
-	struct in_addr src, dst; /* Source and Destination addresses */
+    u_char ttl;		/* Time To Live */
+    u_char proto;		/* Protocol */
+    u_short chksum;		/* Header Checksum */
+    struct in_addr src, dst; /* Source and Destination addresses */
 };
 #define IP_HEADER_LEN(ip)		(((ip)->versionihl) & 0x0f)*4
 
 struct tcp_header {
-	u_short src_port;	/* source port */
-	u_short dst_port;	/* destination port */
-	u_int sequence_num;		/* sequence number */
-	u_int ack_num;		/* acknowledgement number */
-	u_char offset_res_ns;	/*Data offset >> 4 |  res >> 1 | NS 0x01 */
-	u_char flags;			/* Flags */
+    u_short src_port;	/* source port */
+    u_short dst_port;	/* destination port */
+    u_int sequence_num;		/* sequence number */
+    u_int ack_num;		/* acknowledgement number */
+    u_char offset_res_ns;	/*Data offset >> 4 |  res >> 1 | NS 0x01 */
+    u_char flags;			/* Flags */
 #define FIN 0x01
 #define RST 0x04
-	u_short win_size;		/* Window size*/
-	u_short chksum;		/* Checksum */
-	u_short urg;		/* Urgent pointer */
+    u_short win_size;		/* Window size*/
+    u_short chksum;		/* Checksum */
+    u_short urg;		/* Urgent pointer */
 };
 #define TCP_HEADER_LEN(tcp)		(((tcp)->offset_res_ns) >> 4)*4
 
 struct tls_header {
-	u_char type; /* Content Type */
+    u_char type; /* Content Type */
 #define CCS 0x14
 #define ALERT   0x15
 #define HS  0x16
 #define APP 0x17
 #define HB  0x18
-	u_short version; /* Version */
-	u_short len; /* Length */
-	u_char msg; /* Message Type */
+    u_short version; /* Version */
+    u_short len; /* Length */
+    u_char msg; /* Message Type */
 #define CLIENT_HELLO 0x01
 #define FINISHED 0x14
 };
@@ -84,47 +84,47 @@ struct tls_header {
 #define CLIENT_HELLO_HEADER_LEN 6
 
 struct packet_info {
-	const struct ip_header *ip_hdr;
-	struct tcp_header *tcp_hdr;
-	const struct tls_header *record_hdr;
+    const struct ip_header *ip_hdr;
+    struct tcp_header *tcp_hdr;
+    const struct tls_header *record_hdr;
 
-	uint32_t size_tcp_hdr;
-	uint32_t size_ip_hdr;
+    uint32_t size_tcp_hdr;
+    uint32_t size_ip_hdr;
 
-	uint8_t *app_data;
-	uint16_t app_data_len;
+    uint8_t *app_data;
+    uint16_t app_data_len;
 };
 
 struct __attribute__((__packed__)) slitheen_header {
-	uint64_t counter;
-	uint16_t stream_id; /* determines which stream the data is from */
-	uint16_t len;
-	uint16_t garbage;
-	uint16_t zeros;
+    uint64_t counter;
+    uint16_t stream_id; /* determines which stream the data is from */
+    uint16_t len;
+    uint16_t garbage;
+    uint16_t zeros;
 };
 
 #define SLITHEEN_HEADER_LEN 16
 
 struct __attribute__((__packed__)) record_header {
-	u_char type;
+    u_char type;
 #define HS 0x16
-	u_short version;
-	u_short len;
+    u_short version;
+    u_short len;
 };
 #define RECORD_LEN(rec)		(htons(rec->len))
 
 struct __attribute__((__packed__)) handshake_header {
-	u_char type; /*Handshake message type */
-	u_char len1;
-	u_char len2;
-	u_char len3;
+    u_char type; /*Handshake message type */
+    u_char len1;
+    u_char len2;
+    u_char len3;
 };
 #define HANDSHAKE_MESSAGE_LEN(hs)		(((hs)->len1) << 16)+(((hs)->len2) << 8)+ ((hs)->len3)
 #define HANDSHAKE_HEADER_LEN 4
 
 struct sniff_args {
-	char *readdev;
-	char *writedev;
+    char *readdev;
+    char *writedev;
 };
 
 struct inject_args {

+ 5 - 5
relay_station/util.c

@@ -41,7 +41,7 @@ void *emalloc(size_t size){
     void *ptr = malloc(size);
     if (ptr == NULL){
         fprintf(stderr, "Memory failure. Exiting...\n");
-	exit(1);
+        exit(1);
     }
 
     return ptr;
@@ -105,7 +105,7 @@ void *dequeue(queue *list){
 
     void *data = list->first->data;
     element *target =list->first;
-    
+
     list->first = target->next;
 
     free(target);
@@ -122,7 +122,7 @@ void *dequeue(queue *list){
  */
 
 void *peek(queue *list, int32_t n){
-    
+
     int32_t i;
     element *target = list->first;
 
@@ -151,9 +151,9 @@ void remove_queue(queue *list){
     while(data != NULL){
         free(data);
         data = dequeue(list);
-    
+
     }
-    
+
     free(list);
 }
 

Some files were not shown because too many files changed in this diff