Permalink
Browse files

Expiration of connections and fragments

  • Loading branch information...
1 parent 24b09b4 commit 95bfbe93e21f598d185dd5a71f3b8070e690a888 @xHire committed Jul 21, 2012
Showing with 459 additions and 138 deletions.
  1. +1 −1 configure.ac
  2. +13 −2 src/icmp.c
  3. +29 −5 src/linkedlist.c
  4. +5 −1 src/linkedlist.h
  5. +213 −86 src/nat.c
  6. +21 −8 src/nat.h
  7. +3 −2 src/radixtree.c
  8. +133 −24 src/tcp.c
  9. +11 −0 src/tcp.h
  10. +12 −3 src/udp.c
  11. +18 −6 src/wrapper.c
View
@@ -21,7 +21,7 @@ AC_ARG_ENABLE([debug],
[debug=no])
if test "x$debug" = "xyes"; then
- AM_CFLAGS="${AM_CFLAGS} -g -ggdb -O0 -pipe -pedantic -Wshadow -Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -Wold-style-definition -Wdeclaration-after-statement -Wmissing-declarations -Wmissing-prototypes -Wredundant-decls -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Winline -Wformat-nonliteral -Wformat-security -Wswitch-enum -Wswitch-default -Winit-self -Wmissing-include-dirs -Wundef -Waggregate-return -Wnested-externs -Wunsafe-loop-optimizations"
+ AM_CFLAGS="${AM_CFLAGS} -g -ggdb -O0 -pipe -pedantic -Wshadow -Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -Wold-style-definition -Wdeclaration-after-statement -Wmissing-declarations -Wmissing-prototypes -Wredundant-decls -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Winline -Wformat-nonliteral -Wformat-security -Wswitch-enum -Winit-self -Wmissing-include-dirs -Wundef -Waggregate-return -Wnested-externs -Wunsafe-loop-optimizations"
AC_DEFINE([DEBUG])
else
AM_CFLAGS="${AM_CFLAGS} -O2"
View
@@ -24,6 +24,7 @@
#include "checksum.h"
#include "icmp.h"
#include "ipv6.h"
+#include "linkedlist.h"
#include "log.h"
#include "nat.h"
#include "transmitter.h"
@@ -86,6 +87,8 @@ int icmp_ipv4(struct s_ethernet *eth4, struct s_ipv4 *ip4,
return 1;
}
+ linkedlist_move2end(timeout_icmp, connection->llnode);
+
echo->id = connection->ipv6_port_src;
/* override information in original ICMP header */
@@ -189,14 +192,23 @@ int icmp_ipv6(struct s_ethernet *eth6, struct s_ipv6 *ip6, char *payload)
connection = nat_out(nat6_icmp, nat4_icmp,
eth6->src,
ip6->ip_src, ip6->ip_dest,
- echo->id, 0);
+ echo->id, 0, 1);
if (connection == NULL) {
log_warn("Outgoing connection wasn't "
"found/created in NAT!");
return 1;
}
+ if (connection->llnode == NULL) {
+ connection->llnode =
+ linkedlist_append(timeout_icmp,
+ connection);
+ } else {
+ linkedlist_move2end(timeout_icmp,
+ connection->llnode);
+ }
+
echo->id = connection->ipv4_port_src;
/* override information in original ICMP header */
@@ -280,7 +292,6 @@ int icmp_ndp(struct s_ethernet *ethq, struct s_ipv6 *ipq,
/* first check whether the request belongs to us */
if (memcmp(&wrapsix_ipv6_prefix, &ndp_ns->target, 12) != 0) {
- log_debug("This is unfamiliar NDP packet");
return 1;
}
View
@@ -17,6 +17,7 @@
*/
#include <stdlib.h> /* free, malloc */
+#include <time.h> /* time, time_t */
#include "linkedlist.h"
#include "log.h"
@@ -65,27 +66,28 @@ void linkedlist_destroy(linkedlist_t *root)
* @param root Root of the linked list
* @param data Data to append to the list
*
- * @return 0 for success
- * @return 1 for failure
+ * @return pointer to created node if succeeded
+ * @return NULL if failed
*/
-int linkedlist_append(linkedlist_t *root, void *data)
+linkedlist_node_t *linkedlist_append(linkedlist_t *root, void *data)
{
linkedlist_node_t *node;
if ((node = (linkedlist_node_t *) malloc(sizeof(linkedlist_node_t))) ==
NULL) {
log_error("Lack of free memory");
- return 1;
+ return NULL;
}
node->data = data;
+ node->time = time(NULL);
node->prev = root->last.prev;
node->next = &root->last;
root->last.prev->next = node;
root->last.prev = node;
- return 0;
+ return node;
}
/**
@@ -102,3 +104,25 @@ void linkedlist_delete(linkedlist_t *root, linkedlist_node_t *node)
free(node);
node = NULL;
}
+
+/**
+ * Move a node to the end of linked list. It's possible to even move it to
+ * another linked list.
+ *
+ * @param root Root of the linked list
+ * @param node Node to move to the end
+ */
+void linkedlist_move2end(linkedlist_t *root, linkedlist_node_t *node)
+{
+ /* take the node out */
+ node->next->prev = node->prev;
+ node->prev->next = node->next;
+
+ /* put it to the end */
+ node->prev = root->last.prev;
+ node->next = &root->last;
+ root->last.prev->next = node;
+ root->last.prev = node;
+
+ node->time = time(NULL);
+}
View
@@ -19,11 +19,14 @@
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
+#include <time.h> /* time_t */
+
/* Linked list node structure */
typedef struct s_linkedlist_node {
struct s_linkedlist_node *prev;
struct s_linkedlist_node *next;
void *data;
+ time_t time;
} linkedlist_node_t;
/* Linked list root structure */
@@ -34,7 +37,8 @@ typedef struct s_linkedlist {
linkedlist_t *linkedlist_create(void);
void linkedlist_destroy(linkedlist_t *root);
-int linkedlist_append(linkedlist_t *root, void *data);
+linkedlist_node_t *linkedlist_append(linkedlist_t *root, void *data);
void linkedlist_delete(linkedlist_t *root, linkedlist_node_t *node);
+void linkedlist_move2end(linkedlist_t *root, linkedlist_node_t *node);
#endif /* LINKEDLIST_H */
Oops, something went wrong.

0 comments on commit 95bfbe9

Please sign in to comment.