char * parse_address(struct olsrv2 *olsr, struct address_list **list, char *msg_ptr, char *num_addr) { struct address_block_info info; struct address_list *new_list = NULL, *tail = NULL; int i; union olsr_ip_addr mid; msg_ptr = get_address_block_header(olsr, &info, msg_ptr); debug_code(print_address_block_info(olsr, &info)); *num_addr = info.num_addr;// use after tail = NULL; for (i = 0; i < info.num_addr; i++) { new_list = (struct address_list *)olsr_malloc(sizeof(struct address_list), __FUNCTION__); memset(new_list, 0, sizeof(struct address_list)); memset(&mid, 0, sizeof(union olsr_ip_addr)); new_list->next = NULL; new_list->index = i; msg_ptr = get_bytes(msg_ptr, info.mid_length, &mid); make_address(&new_list->ip_addr, &mid, &info); debug_code(print_new_list(olsr, new_list)); // QUEUE address if (*list == NULL){ *list = new_list; //tail = new_list; }else{ new_list->next = *list; *list = new_list; //tail->next = new_list; //tail = new_list; } } debug_code(print_address_list(olsr, *list)); return msg_ptr; }
static olsr_bool process_tc(struct olsrv2 *olsr, struct tc_message *tc, union olsr_ip_addr *in_if ) { struct tc_mpr_addr *mpr_selector = NULL; OLSR_LIST *tmpList = NULL; OLSR_LIST_ENTRY *tmpEntry = NULL; OLSR_TOPOLOGY_TUPLE *tmpTuple = NULL; ATTACHED_NETWORK *attached_net_entry = NULL; char* paddr; if(DEBUG_OLSRV2) { olsr_printf("\tProcess TOPOLOGY MESSAGE\n"); } /* //codexxx' // before processing TC message add the queue length of the corresponding originator to the OLSR_LIST "queue_set" olsr_bool IPfound = OLSR_FALSE; struct queue_info *queueInf = NULL, *tempo= NULL ; OLSR_LIST_ENTRY *queueEntry = NULL; queueInf = (queue_info *)olsr_malloc(sizeof(queue_info), __FUNCTION__); queueInf->orig_IP = tc->originator; queueInf->Qlength = tc->queuelength; if(olsr->queue_set.numEntry == 0) { // insert to the list directly OLSR_InsertList(&olsr->queue_set,queueInf,sizeof(queue_info)); }else{ // liste deja contient des element ...donc trouver si deja existe queueEntry = olsr->queue_set.head ; while(queueEntry != NULL) ///// { tempo = (queue_info *)queueEntry->data ; if(!cmp_ip_addr(olsr,&tempo->orig_IP,&queueInf->orig_IP)) //// { // on a trouver cet originator IP ds la liste alors update le queue et sortir de la boucle tempo->Qlength = queueInf->Qlength; IPfound = OLSR_TRUE; break; } queueEntry = queueEntry->next ; } if(IPfound == OLSR_FALSE) { // cet IP n'existe pas deja dans la liste => l'introduire OLSR_InsertList(&olsr->queue_set,queueInf,sizeof(queue_info)); } } //end codexxx' */ //13.1.1 if (lookup_link_status(olsr, &tc->source_addr) != SYMMETRIC) { if(DEBUG_OLSRV2) { paddr = olsr_niigata_ip_to_string(olsr, &tc->source_addr); olsr_printf("\tsource addr:%s isn't sym neigh\n",paddr); free(paddr); } return OLSR_FALSE; } //13.1.2 //check previous :look tc_change_structure //13.1.3 if ((tmpList = lookup_topology_set(olsr, &tc->originator)) != NULL){ tmpEntry = (OLSR_LIST_ENTRY *)tmpList->head; while (tmpEntry) { tmpTuple = (OLSR_TOPOLOGY_TUPLE *)tmpEntry->data; if (tmpTuple->T_seq > tc->assn){ OLSR_DeleteList_Search(tmpList); if(DEBUG_OLSRV2) { olsr_printf("\t\tThis message is OLD.Skipped\n"); } return OLSR_FALSE; } tmpEntry = tmpEntry->next; } OLSR_DeleteList_Search(tmpList); } //13.1.4 mpr_selector = tc->mpr_selector_address; while (mpr_selector){ proc_topology_set(olsr, &mpr_selector->address, &tc->originator, tc->assn, OLSR_FALSE); mpr_selector = mpr_selector->next; } //updating the attached network set attached_net_entry = tc->attached_net_addr; while(attached_net_entry){ proc_attached_set(olsr, &attached_net_entry->network_addr, attached_net_entry->prefix_length, &tc->originator, tc->assn); attached_net_entry = attached_net_entry->next; } debug_code(print_attached_set(olsr)); if(proc_forward_set(olsr, &tc->originator, &tc->source_addr, tc->message_seq_number) == OLSR_TRUE){ forward_message(olsr); } return OLSR_TRUE; }
static olsr_bool tc_change_structure(struct olsrv2 *olsr, struct tc_message *tc_msg, struct message_header *m, union olsr_ip_addr *source) { struct address_tuple *tmp_addr_entry = NULL; struct tlv_tuple *tlv_entry = NULL; struct tc_mpr_addr *mpr_entry = NULL; int i; ATTACHED_NETWORK *attached_net_entry = NULL; OLSR_LOCAL_INTERFACE_BLOCK_ENTRY local_iface_entry; // initialize memset(tc_msg, 0, sizeof(struct tc_message)); // fill ipv4 header informations tlv_entry = get_msg_tlv(olsr, Validity_Time); if(tlv_entry->length == 1) tc_msg->vtime = me_to_double((olsr_u8_t)tlv_entry->value); else// greater than 3 byte tc_msg->vtime = get_validity_time_from_hop(tlv_entry, m->hop_count); olsr_ip_copy(olsr, &tc_msg->source_addr, source); olsr_ip_copy(olsr, &tc_msg->originator, &m->orig_addr); tc_msg->message_seq_number = m->message_seq_num; tc_msg->hop_count = m->hop_count; tc_msg->ttl = m->ttl; if ((tlv_entry = get_msg_tlv(olsr, Content_Sequence_Number)) == NULL){ olsr_error("This Message include no ASSN\n"); }else{//assume that assn is less equal than 4byte tc_msg->assn = (olsr_u16_t)tlv_entry->value; } /* //codexxx' tlv_entry = get_msg_tlv(olsr, queuelen); tc_msg->queuelength = (olsr_u8_t)tlv_entry->value; //end codexxx' */ if(proc_assn_history_set(olsr, &tc_msg->originator, tc_msg->assn)){ free_all_address_entries(olsr); free_message_tlv(olsr); olsr_free_tc_packet(tc_msg); return OLSR_FALSE; } //local interface block OLSR_InitList(&tc_msg->local_iface_list); tmp_addr_entry = olsr->local_interface_block_entry; while(tmp_addr_entry) { olsr_ip_copy(olsr, &local_iface_entry.iface_addr, &tmp_addr_entry->ip_addr); local_iface_entry.other_if = OLSR_FALSE; tlv_entry = tmp_addr_entry->addr_tlv; while(tlv_entry) { switch(tlv_entry->type){ case Other_If: if(tlv_entry->value == OLSR_TRUE) local_iface_entry.other_if = OLSR_TRUE; break; default: break; } tlv_entry = tlv_entry->next; } OLSR_InsertList(&tc_msg->local_iface_list, &local_iface_entry, sizeof(OLSR_LOCAL_INTERFACE_BLOCK_ENTRY)); tmp_addr_entry= tmp_addr_entry->next; } // all mpr selector : advertized by tc tc_msg->mpr_selector_address = NULL; tc_msg->attached_net_addr = NULL; for (i = 0; i < olsr->num_of_addr_tlv_block_entries; ++i){ tmp_addr_entry = olsr->addr_tlv_block_entries[i]; tlv_entry = NULL; while (tmp_addr_entry){ //attached network address if((tlv_entry = have_attached_network_tlv(tmp_addr_entry->addr_tlv)) != NULL) { attached_net_entry = (ATTACHED_NETWORK *)olsr_malloc( sizeof(ATTACHED_NETWORK), __FUNCTION__); memset(attached_net_entry, 0 , sizeof(ATTACHED_NETWORK)); attached_net_entry->next = NULL; olsr_ip_copy(olsr, &attached_net_entry->network_addr, &tmp_addr_entry->ip_addr); attached_net_entry->prefix_length = (olsr_u8_t)tlv_entry->value; //queue if(tc_msg->attached_net_addr == NULL) tc_msg->attached_net_addr = attached_net_entry; else{ attached_net_entry->next = tc_msg->attached_net_addr; tc_msg->attached_net_addr = attached_net_entry; } tmp_addr_entry = tmp_addr_entry->next; continue; } mpr_entry = (struct tc_mpr_addr *)olsr_malloc(sizeof(struct tc_mpr_addr), __FUNCTION__); memset(mpr_entry, 0, sizeof(struct tc_mpr_addr)); olsr_ip_copy(olsr, &mpr_entry->address, &tmp_addr_entry->ip_addr); if (tc_msg->mpr_selector_address == NULL){//first tc_msg->mpr_selector_address = mpr_entry; mpr_entry->next = NULL; }else{ mpr_entry->next = tc_msg->mpr_selector_address; tc_msg->mpr_selector_address = mpr_entry; } tmp_addr_entry = tmp_addr_entry->next; } }//for debug_code(print_tc_message(olsr, tc_msg)); //free address tlv & message tlv free_all_address_entries(olsr); free_message_tlv(olsr); return OLSR_TRUE; }
char * parse_address_tlv(struct olsrv2 *olsr, struct tlv_tuple_local **tlv_list, char *msg_ptr, const char num_addr) { struct tlv_info info; olsr_u16_t tlv_length; char *tlv_end = NULL; struct tlv_tuple_local *new_list = NULL; // get tlv_length msg_ptr = get_u16(msg_ptr, &tlv_length); if (tlv_length == 0) { if(DEBUG_OLSRV2) { olsr_printf("MSG includes no TLV\n"); } return msg_ptr; } tlv_end = msg_ptr + tlv_length; if(DEBUG_OLSRV2) { olsr_printf("TLV LENGTH[%u]\tStart[%p]\t\tEnd[%p]\n", tlv_length, msg_ptr, tlv_end); } while (msg_ptr < tlv_end) { new_list = (struct tlv_tuple_local *)olsr_malloc(sizeof(struct tlv_tuple_local), __FUNCTION__); memset(new_list, 0, sizeof(struct tlv_tuple_local)); new_list->next = NULL; new_list->value = OLSR_FALSE; new_list->multi_value = NULL; new_list->extended_value = NULL; // <type> msg_ptr = get_u8(msg_ptr, &info.type); // calc userbit &type calc_user_bit(&info); // <semantics> msg_ptr = get_u8(msg_ptr, &info.semantics); calc_semantics(&info); //set semantics new_list->semantics = info.semantics; debug_code(print_tlv_infomations(olsr, &info)); //check semantics consitency(packetbb 5.3.1) //update 0913 if (info.no_value_bit == 1 && info.extended_bit == 1) { if(DEBUG_OLSRV2) { olsr_printf("This TLV is not correct1\n"); } free(new_list); return tlv_end; } if (info.no_index_bit == 1 && info.single_index_bit == 1) { if(DEBUG_OLSRV2) { olsr_printf("This TLV is not correct2\n"); } free(new_list); return tlv_end; } //fill the struct //type new_list->type = info.type; //index start & stop if(info.single_index_bit == 1) // single index bit set to 1 { msg_ptr = get_u8(msg_ptr, &new_list->index_start); new_list->index_stop = new_list->index_start; }else{ //single index bit set to 0 //in case of no index bit set or unset if(info.no_index_bit == 0){ msg_ptr = get_u8(msg_ptr, &new_list->index_start); msg_ptr = get_u8(msg_ptr, &new_list->index_stop); }else{ new_list->index_start = 0; new_list->index_stop = num_addr -1; } } //length if(info.no_value_bit == 1){ // no value bit set to 1 new_list->length = 0; new_list->value = OLSR_TRUE; new_list->multi_value = NULL; new_list->extended_value = NULL; }else{ // no value bit set to 0 // in case of extended bit set or unset if(info.extended_bit == 0){ olsr_u8_t tmp; msg_ptr = get_u8(msg_ptr, &tmp); new_list->length = tmp; }else{ olsr_u16_t tmp; msg_ptr = get_u16(msg_ptr, &tmp); new_list->length = tmp; } } //check incosistency if(new_list->index_start > new_list->index_stop){ if(DEBUG_OLSRV2) { olsr_printf("index_start > index_stop\n"); } free(new_list); return tlv_end; } new_list->number_value = new_list->index_stop - new_list->index_start + 1; //get value if(info.no_value_bit == 0){ // in case of multi value bit set or unset if(info.multi_value_bit == 0){ new_list->one_field_size = new_list->length; //check invalid info if(check_length_over_limit(msg_ptr, tlv_end, new_list->length) == OLSR_FALSE){ olsr_printf("\n\tWarning : Invalid Message [ length is too long(%u)] %s(%u)\n", new_list->length, __FUNCTION__, __LINE__); free(new_list); return tlv_end; } msg_ptr = get_address_tlv_value(msg_ptr, new_list); new_list->multi_value_bit = 0; }else{ new_list->multi_value_bit = 1; new_list->one_field_size = new_list->length / new_list->number_value; //check invalid info if(check_length_over_limit(msg_ptr, tlv_end, new_list->length) == OLSR_FALSE){ olsr_printf("\n\tWarning : Invalid Message [ length is too long(%u)] %s(%u)\n", new_list->length, __FUNCTION__, __LINE__); free(new_list); return tlv_end; } msg_ptr = get_multi_value_address_tlv(msg_ptr, new_list); } } debug_code(print_address_tlv_tuple(olsr, new_list)); // QUEUE the Message TLV if (*tlv_list == NULL) *tlv_list = new_list; else { new_list->next = *tlv_list; *tlv_list = new_list; } }//while debug_code(print_address_tlv(olsr, *tlv_list)); if (msg_ptr != tlv_end) return tlv_end; return msg_ptr; }
/* ** parser : message tlv */ char * parse_message_tlv(struct olsrv2 *olsr, char *msg_ptr) { struct tlv_info info; olsr_u16_t tlv_length; char *tlv_end = NULL; struct tlv_tuple *new_tuple = NULL; // get tlv_length msg_ptr = get_u16(msg_ptr, &tlv_length); // Msg include no TLV if (tlv_length == 0) { if(DEBUG_OLSRV2) { olsr_printf("Msg include no MSG TLV\n"); } return msg_ptr; } tlv_end = msg_ptr + tlv_length; if(DEBUG_OLSRV2) { olsr_printf("MessageTLVLength[%u]\tStart[%p]\tEnd[%p]\n", tlv_length, msg_ptr, tlv_end); } while (msg_ptr < tlv_end) { //create new tlv tuple new_tuple = (struct tlv_tuple *)olsr_malloc(sizeof(struct tlv_tuple), __FUNCTION__); memset(new_tuple, 0, sizeof(struct tlv_tuple)); new_tuple->next = NULL; new_tuple->value = OLSR_FALSE; new_tuple->extended_value = NULL; //get type field value msg_ptr = get_u8(msg_ptr, &info.type); // calc userbit & type calc_user_bit(&info); // get semantics field value msg_ptr = get_u8(msg_ptr, &info.semantics); calc_semantics(&info); debug_code(print_tlv_infomations(olsr, &info)); //check semantic consistency(packetbb 5.3.1) //update 0913 if (info.no_value_bit == 1 && info.extended_bit == 1){ if(DEBUG_OLSRV2) { olsr_printf("This TLV is not correct1.\n"); } free(new_tuple); return tlv_end; } if(info.no_index_bit == 1 && info.single_index_bit == 1){ if(DEBUG_OLSRV2) { olsr_printf("This TLV is not correct2.\n"); } free(new_tuple); return tlv_end; } /* if single index bit == 1 , or no_value bit == 1, then multi value bit set to zero */ if( (info.single_index_bit == 1 || info.no_value_bit == 1) && info.multi_value_bit == 1 ) { if(DEBUG_OLSRV2) { olsr_printf("This TLV is not corrent3.\n"); } free(new_tuple); return tlv_end; } //fill the struct new_tuple->type = info.type; if(info.no_value_bit == 1){ new_tuple->length = 0; new_tuple->value = OLSR_TRUE; new_tuple->extended_value = NULL; }else{ //no value bit == 0 if(info.extended_bit == 0){ olsr_u8_t tmp; msg_ptr = get_u8(msg_ptr, &tmp); new_tuple->length = tmp; }else{ olsr_u16_t tmp; msg_ptr = get_u16(msg_ptr, &tmp); new_tuple->length = tmp; } //check invalid info if(check_length_over_limit(msg_ptr, tlv_end, new_tuple->length) == OLSR_FALSE){ olsr_printf("\n\tWarning : Invalid Message [ length is too long (%u) ] %s(%u)\n", new_tuple->length, __FUNCTION__, __LINE__); free(new_tuple); return tlv_end; } msg_ptr = get_tlv_value(msg_ptr, new_tuple); } debug_code(print_message_tlv_tuple(olsr, new_tuple)); //Queue the Message TLV if (olsr->message_tlv_entry == NULL) olsr->message_tlv_entry = new_tuple; else { new_tuple->next = olsr->message_tlv_entry; olsr->message_tlv_entry = new_tuple; } }//while if (msg_ptr != tlv_end) return tlv_end; print_message_tlv(olsr); return msg_ptr; }
int main() { debug_code("public14.a"); return 0; }