u32 dcdm_signature_ac_engine_add_pattern ( dcdm_ac_compile_engine_s * engine, ac_compile_s *ac) { u32 rtn_code = ERROR_SUCCESS; u32 signature_id = 0; dcdm_sig_ac_s *sig_ac = NULL; struct list_head *head = NULL; struct list_head *pos = NULL; struct list_head *n = NULL; dcdm_ac_str_s *ac_str = NULL; head = &(engine->compile_head); list_for_each_safe (pos, n, head) { sig_ac = get_list_entry (pos, dcdm_sig_ac_s, compile); signature_id = sig_ac->signature_id; for(ac_str=sig_ac->head; NULL != ac_str; ac_str=ac_str->next) { rtn_code = ac_compile_add_pattern (ac, ac_str->str, ac_str->str_len, signature_id, sig_ac->pare_id, sig_ac->dir, ac_str->offset, ac_str->within); if(ERROR_SUCCESS != rtn_code) { return rtn_code; } } }
static linked_set_s *hfa_set_nfa2ids (struct list_head *nfaq) { linked_set_s *ids = NULL; nfa_list_s *nfa_list; struct list_head *pos; struct list_head *n; list_for_each_safe (pos, n, nfaq) { nfa_list = get_list_entry (pos, nfa_list_s, list); ids = linked_set_insert (ids, nfa_list->nfa->id); }
u32 addrpool_parse_rule_fin(struct list_head *config_rule_head, struct pc_rule* rule, unsigned long* ruleid, long* node) { unsigned long i = 0; struct list_head *pos, *n; addrpool_config_rule_s *rule_node = NULL; list_for_each_safe (pos, n, config_rule_head) { rule_node = get_list_entry (pos, addrpool_config_rule_s, list); node[i] = rule_node->node; ruleid[i] = i; rule[i].field[0].field_flag = FIELD_FLAG_OTHER; rule[i].field[0].low = rule_node->interface; rule[i].field[0].high = rule_node->interface; rule[i].field[1].field_flag = FIELD_FLAG_OTHER; rule[i].field[1].low = rule_node->ip_min; rule[i].field[1].high = rule_node->ip_max; i++; }
/**************************************************************** Description : Validate connect 'after' being connected @arg : theList client_list that holds all connections @arg : file_desc socket file descriptor of incoming @arg : port port string of incoming connection @return : bool value indicating (un)successful validation {9:References} *****************************************************************/ bool validate_connect(client_list *theList, int file_desc, char *port){ /******* Validate connect cases *********/ client_list *loopList = theList; bool inSipFlag =false; bool alreadyExistFlag =false; bool isSelfFlag=false; bool isServerFlag=false; bool moreThanThree=false; char *ipAddr; //Get ip address while(loopList!=NULL){ if (loopList->file_desc == file_desc) //Dont consider the last entry { ipAddr= loopList->ip_addr; break; } loopList= loopList->cl_next; } /******* Validate if connecting to server *********/ loopList=theList; while(loopList!=NULL){ if (loopList->file_desc != file_desc) //Dont consider the last entry { if (loopList->connection_id==1) { if (strcmp(loopList->ip_addr,ipAddr)==0) { if (strcmp(loopList->port,port)==0) { isServerFlag = true; break; } } } } loopList= loopList->cl_next; } if (isServerFlag) { send_all(file_desc,"41 error-c Connect to server not allowed ",41); client_list *current; get_list_entry(theList,¤t,file_desc); fprintf(stderr, "%s (%s) tried connect. Connection declined.\n", current->host_name,current->ip_addr); return false; } /******* Validate if in sip *********/ loopList = sip_list; while(loopList!=NULL){ if (strcmp(loopList->ip_addr,ipAddr)==0) { if (strcmp(loopList->port,port)==0) { inSipFlag = true; break; } } loopList= loopList->cl_next; } if (!inSipFlag) //checks if self registered too { if (sip_list==NULL) { send_all(file_desc,"50 error-c Destination not registered with server ",50); fprintf(stderr, "Self not registered. Connection declined.\n"); }else{ send_all(file_desc,"38 error-c Not registered with server ",38); client_list *current; get_list_entry(theList,¤t,file_desc); fprintf(stderr, "%s (%s) not registered. Connection declined.\n", current->host_name,current->ip_addr); } return false; } /******* Validate if connection is duplicate *********/ loopList=theList; while(loopList!=NULL){ if (loopList->file_desc != file_desc) //Dont consider the last entry { if (strcmp(loopList->ip_addr,ipAddr)==0) { if (strcmp(loopList->port,port)==0) { alreadyExistFlag = true; break; } } } loopList = loopList->cl_next; } if (alreadyExistFlag) { send_all(file_desc,"29 error-c Already connected ",29); client_list *current; get_list_entry(theList,¤t,file_desc); fprintf(stderr, "%s (%s) already connected. Duplicate connection declined.\n", current->host_name,current->ip_addr); return false; } /******* Validate if connection is to self *********/ commandMyip(); //make sure my_ip_addr is valid if (strcmp(ipAddr,my_ip_addr)==0|| strcmp(ipAddr,"127.0.0.1")==0) { if (strcmp(listening_port,port)==0) { isSelfFlag=1; } } if (isSelfFlag) { client_list *current; get_list_entry(theList,¤t,file_desc); send_all(file_desc,"11 error-c ",11); fprintf(stderr, "%s %s is self. Self connection declined.\n", current->host_name,current->ip_addr); return false; } loopList=theList; int connectionCount =0; while(loopList!=NULL){ if (loopList->file_desc != file_desc) //Dont consider the last entry { connectionCount++; if (connectionCount>3) { moreThanThree=true; } } loopList = loopList->cl_next; } if (moreThanThree) { send_all(file_desc,"52 error-c Destination already connected to 3 peers ",52); client_list *current; get_list_entry(theList,¤t,file_desc); fprintf(stderr, "%s (%s) Maximum connections reached. New connection declined.\n", current->host_name,current->ip_addr); return false; } return true; }