From 13bc1e327af9a38c5979ac100a91627a25767afb Mon Sep 17 00:00:00 2001 From: gonzalef Date: Tue, 24 Mar 2020 18:23:18 +0100 Subject: [PATCH] djgn --- src/node.c | 34 +++++++++++++++++++++++++++++++++- src/node.h | 2 +- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/node.c b/src/node.c index f826554..79aa5e9 100644 --- a/src/node.c +++ b/src/node.c @@ -9,8 +9,40 @@ packet listen_for_packets(){ // We need to make sure the TLV announces a length that will no go onto // another tlv, as we might end up reading bullshit. -int validate_tlvs(union tlv tlv_to_validate){ +int validate_tlv(unsigned char *data, int pos){ + switch(data[pos]) { + case 0: + break; + case 1: + break; + case 2: + if(data[pos+1] != 0) return 0; + break; + case 3: + if(data[pos+1] != 18) return 0; + break; + case 4: + if(data[pos+1] != 16) return 0; + break; + case 5: + if(data[pos+1] != 0) return 0; + break; + case 6: + if(data[pos+1] != 26) return 0; + break; + case 7: + if(data[pos+1] != 8) return 0; + break; + case 8: + if(data[pos+1] < 26 || data[pos+1] > 218) return 0; + break; + case 9: + break; + default: + return 0; + } + return 1; } void work_with_tlvs(struct tlvs_list receivied_tlvs){ diff --git a/src/node.h b/src/node.h index b871865..f7680ad 100644 --- a/src/node.h +++ b/src/node.h @@ -46,7 +46,7 @@ void update_neighbours(); void work_with_tlvs(); -int validate_tlvs(); +int validate_tlv(unsigned char *data, int pos); // threaded functions