Commit cd39efa3 authored by Daniele Lacamera's avatar Daniele Lacamera

Fragments: discard all fragments under memory pressure.

parent 55ae3449
...@@ -237,6 +237,20 @@ static int copy_ipv6_hdrs_nofrag(struct pico_frame* dst, struct pico_frame* src) ...@@ -237,6 +237,20 @@ static int copy_ipv6_hdrs_nofrag(struct pico_frame* dst, struct pico_frame* src)
return retval; return retval;
} }
static void pico_fragment_tree_mempressure_cleanup(void)
{
pico_fragment_t * fragment = NULL;
struct pico_tree_node *idx = NULL;
struct pico_tree_node *tmp = NULL;
dbg("Frag module: under memory pressure. Discarding all fragments.\n");
pico_tree_foreach_safe(idx, &pico_fragments, tmp) {
fragment = idx->keyValue;
pico_fragment_free(fragment);
}
}
void pico_ipv6_process_frag(struct pico_ipv6_exthdr *exthdr, struct pico_frame *f, uint8_t proto /* see pico_addressing.h */) void pico_ipv6_process_frag(struct pico_ipv6_exthdr *exthdr, struct pico_frame *f, uint8_t proto /* see pico_addressing.h */)
{ {
...@@ -343,7 +357,7 @@ void pico_ipv6_process_frag(struct pico_ipv6_exthdr *exthdr, struct pico_frame * ...@@ -343,7 +357,7 @@ void pico_ipv6_process_frag(struct pico_ipv6_exthdr *exthdr, struct pico_frame *
} }
else else
{ {
/* TODO: */ pico_fragment_tree_mempressure_cleanup();
} }
} }
} }
...@@ -483,7 +497,7 @@ int pico_ipv4_process_frag(struct pico_ipv4_hdr *hdr, struct pico_frame *f, uint ...@@ -483,7 +497,7 @@ int pico_ipv4_process_frag(struct pico_ipv4_hdr *hdr, struct pico_frame *f, uint
} }
else else
{ {
/* TODO: */ pico_fragment_tree_mempressure_cleanup();
} }
} }
} }
...@@ -742,7 +756,6 @@ static void pico_ip_frag_expired(pico_time now, void *arg) ...@@ -742,7 +756,6 @@ static void pico_ip_frag_expired(pico_time now, void *arg)
//TODO: what does IPV4 expect? //TODO: what does IPV4 expect?
} }
fragment->frame = NULL;
pico_fragment_free(fragment); pico_fragment_free(fragment);
fragment=NULL; fragment=NULL;
} }
...@@ -762,6 +775,9 @@ static void pico_ip_frag_expired(pico_time now, void *arg) ...@@ -762,6 +775,9 @@ static void pico_ip_frag_expired(pico_time now, void *arg)
// note: offset and more flag are located differently in ipv4(iphdr) and ipv6(exthdr) // note: offset and more flag are located differently in ipv4(iphdr) and ipv6(exthdr)
// offset is expressed in octets (bytes) (not the 8 byte unit used in ip) // offset is expressed in octets (bytes) (not the 8 byte unit used in ip)
//
static int pico_fragment_arrived(pico_fragment_t* fragment, struct pico_frame* frame, uint16_t offset, uint16_t more ) static int pico_fragment_arrived(pico_fragment_t* fragment, struct pico_frame* frame, uint16_t offset, uint16_t more )
{ {
...@@ -855,6 +871,8 @@ static int pico_fragment_arrived(pico_fragment_t* fragment, struct pico_frame* f ...@@ -855,6 +871,8 @@ static int pico_fragment_arrived(pico_fragment_t* fragment, struct pico_frame* f
frag_dbg("[LUM:%s:%d] Failed to allocate frame buffer \n",__FILE__,__LINE__ ); frag_dbg("[LUM:%s:%d] Failed to allocate frame buffer \n",__FILE__,__LINE__ );
// discard packet: no more memory // discard packet: no more memory
pico_fragment_free(fragment); pico_fragment_free(fragment);
pico_fragment_tree_mempressure_cleanup();
return -1; return -1;
// notify icmp // notify icmp
} }
......
...@@ -11,7 +11,7 @@ uint32_t cur_mem, max_mem; ...@@ -11,7 +11,7 @@ uint32_t cur_mem, max_mem;
static int called_atexit = 0; static int called_atexit = 0;
static void memory_stats(void) void memory_stats(void)
{ {
fprintf(stderr, " ################ MAX MEMORY USED in this test: %u\n", max_mem); fprintf(stderr, " ################ MAX MEMORY USED in this test: %u\n", max_mem);
......
...@@ -128,5 +128,7 @@ static inline void PICO_IDLE(void) ...@@ -128,5 +128,7 @@ static inline void PICO_IDLE(void)
usleep(5000); usleep(5000);
} }
void memory_stats(void);
#endif /* PICO_SUPPORT_POSIX */ #endif /* PICO_SUPPORT_POSIX */
...@@ -44,6 +44,10 @@ ...@@ -44,6 +44,10 @@
#include <fcntl.h> #include <fcntl.h>
#include <libgen.h> #include <libgen.h>
#ifdef FAULTY
#include "pico_faulty.h"
#endif
void app_udpecho(char *args); void app_udpecho(char *args);
void app_tcpecho(char *args); void app_tcpecho(char *args);
void app_udpclient(char *args); void app_udpclient(char *args);
...@@ -103,6 +107,7 @@ void deferred_exit(pico_time __attribute__((unused)) now, void *arg) ...@@ -103,6 +107,7 @@ void deferred_exit(pico_time __attribute__((unused)) now, void *arg)
} }
/** From now on, parsing the command line **/ /** From now on, parsing the command line **/
#define NXT_MAC(x) ++ x[5] #define NXT_MAC(x) ++ x[5]
...@@ -641,6 +646,9 @@ int main(int argc, char **argv) ...@@ -641,6 +646,9 @@ int main(int argc, char **argv)
usage(argv[0]); usage(argv[0]);
} }
#ifdef FAULTY
atexit(memory_stats);
#endif
printf("%s: launching PicoTCP loop\n", __FUNCTION__); printf("%s: launching PicoTCP loop\n", __FUNCTION__);
while(1) { while(1) {
pico_stack_tick(); pico_stack_tick();
......
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