char *GetCommaWord(char *Src,char *Word,char Separator) { int WordPos,SkipBrackets; if (*Src==0) return NULL; SkipBrackets=FALSE; for (WordPos=0;*Src!=0;Src++,WordPos++) { if (*Src=='[' && strchr(Src+1,']')!=NULL) SkipBrackets=TRUE; if (*Src==']') SkipBrackets=FALSE; if (*Src==Separator && !SkipBrackets) { Word[WordPos]=0; Src++; while (__isspace(*Src)) Src++; return Src; } else Word[WordPos]=*Src; } Word[WordPos]=0; return Src; }
unsigned long inet_addr(char *inetString) { unsigned long val, base, n; char c; unsigned long parts[MAX_PARTS]; unsigned long *pp; /* If null inet string */ if (inetString == NULL) { errnoSet(S_inetLib_ILLEGAL_INTERNET_ADDRESS); return ERROR; } /* End if null inet string */ /* Initialize locals */ pp = parts; again: val = 0; base = 10; /* If zero prefix */ if (*inetString == '0') { base = 8; inetString++; /* If hexadecimal prefix */ if ( (*inetString == 'x') || (*inetString == 'X') ) { base = 16; inetString++; } /* End if hexadecimal prefix */ } /* End if zero prefix */ /* While not string terminator */ while ( (c = *inetString) ) { /* If digit */ if ( __isdigit((int) c) ) { val = (val * base) + (c - '0'); inetString++; continue; } /* End if digit */ /* If hexadecimal digit */ if ( __isxdigit((int) c) ) { val = (val << 4) + (c + 10 - (__islower((int) c) ? 'a' : 'A')); inetString++; continue; } /* End if hexadecimal digit */ /* If here break loop */ break; } /* End while not string terminator */ /* If dot found */ if (*inetString == '.') { /* If string to large or value to large */ if ( (pp >= parts + (MAX_PARTS - 1)) || (val > 0xff) ) { errnoSet(S_inetLib_ILLEGAL_INTERNET_ADDRESS); return ERROR; } /* End if string to large or value to large */ /* Store value */ *pp++ = val; /* Advance */ inetString++; /* Find next value */ goto again; } /* End if dot found */ /* If trailing character */ if ( (*inetString) && !(__isspace((int) *inetString)) ) { errnoSet(S_inetLib_ILLEGAL_INTERNET_ADDRESS); return ERROR; } /* End if trailing character */ /* Store value */ *pp++ = val; n = pp - parts; /* Select parts number */ switch (n) { /* 32 bit address */ case 1: val = parts[0]; break; /* 8.24 bits address */ case 2: /* If value to large */ if (val > 0xffffff) { errnoSet(S_inetLib_ILLEGAL_INTERNET_ADDRESS); return ERROR; } /* End if value to large */ /* Store value */ val = (parts[0] << 24) | parts[1]; break; /* 8.8.16 bits address */ case 3: /* If value to large */ if (val > 0xffff) { errnoSet(S_inetLib_ILLEGAL_INTERNET_ADDRESS); return ERROR; } /* End if value to large */ /* Store value */ val = (parts[0] << 24) | (parts[1] << 16) | parts[2]; break; /* 8.8.8.8 bits */ case 4: /* If value to large */ if (val > 0xff) { errnoSet(S_inetLib_ILLEGAL_INTERNET_ADDRESS); return ERROR; } /* End if value to large */ /* Store value */ val = (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8) | parts[3]; break; default: errnoSet(S_inetLib_ILLEGAL_INTERNET_ADDRESS); return ERROR; } /* End select part number */ return htonl(val); }
int vfscanf(FILE *fp, const char *format, va_list ap) { #ifdef INCLUDE_LONG_LONG #define STRTO_L_(s,e,b,u) _strto_ll(s,e,b,u) #define MAX_DIGITS 64 #define UV_TYPE unsigned long long #define V_TYPE long long #else #define STRTO_L_(s,e,b,u) _strto_l(s,e,b,u) #define MAX_DIGITS 32 #define UV_TYPE unsigned long #define V_TYPE long #endif #ifdef INCLUDE_FLOAT long double ld; #endif UV_TYPE uv; struct scan_cookie sc; unsigned const char *fmt; const char *p; unsigned char *b; void *vp; int cc, i, cnt; signed char lval; unsigned char store, usflag, base, invert, r0, r1; unsigned char buf[MAX_DIGITS+2]; unsigned char scanset[UCHAR_MAX + 1]; init_scan_cookie(&sc,fp); fmt = (unsigned const char *) format; cnt = 0; while (*fmt) { store = 1; lval = 0; sc.width = INT_MAX; if (*fmt == '%') { /* Conversion specification. */ ++fmt; if (*fmt == '*') { /* Suppress assignment. */ store = 0; ++fmt; } for (i = 0 ; __isdigit(*fmt) ; sc.width = i) { i = (i * 10) + (*fmt++ - '0'); /* Get specified width. */ } for (i = 0 ; i < sizeof(qual_s) ; i++) { /* Optional qualifier. */ if (qual_s[i] == *fmt) { ++fmt; lval += qsz[i]; if ((i < 2) && (qual_s[i] == *fmt)) { /* Double h or l. */ ++fmt; lval += qsz[i]; } break; } } for (p = spec_s ; *p ; p++) { /* Process format specifier. */ if (*fmt != *p) continue; if (p-spec_s < 1) { /* % - match a '%'*/ goto matchchar; } if (p-spec_s < 2) { /* n - store number of chars read */ *(va_arg(ap, int *)) = sc.nread; scan_getc_nw(&sc); goto nextfmt; } if (p-spec_s > 3) { /* skip white space if not c or [ */ while (__isspace(scan_getc_nw(&sc))) {} scan_ungetc(&sc); } if (p-spec_s < 5) { /* [,c,s - string conversions */ invert = 0; if (*p == 'c') { invert = 1; if (sc.width == INT_MAX) { sc.width = 1; } } for (i=0 ; i<= UCHAR_MAX ; i++) { scanset[i] = ((*p == 's') ? (__isspace(i) == 0) : 0); } if (*p == '[') { /* need to build a scanset */ if (*++fmt == '^') { invert = 1; ++fmt; } if (*fmt == ']') { scanset[(int)']'] = 1; ++fmt; } r0 = 0; while (*fmt && *fmt !=']') { /* build scanset */ if ((*fmt == '-') && r0 && (fmt[1] != ']')) { /* range */ ++fmt; if (*fmt < r0) { r1 = r0; r0 = *fmt; } else { r1 = *fmt; } for (i=r0 ; i<= r1 ; i++) { scanset[i] = 1; } r0 = 0; } else { r0 = *fmt; scanset[r0] = 1; } ++fmt; } if (!*fmt) { /* format string exhausted! */ goto done; } } /* ok -- back to common work */ if (sc.width <= 0) { goto done; } if (store) { b = va_arg(ap, unsigned char *); } else { b = buf; } cc = scan_getc(&sc); if (cc <= 0) { scan_ungetc(&sc); goto done; /* return EOF if cnt == 0 */ } i = 0; while ((cc>0) && (scanset[cc] != invert)) { i = 1; /* yes, we stored something */ *b = cc; b += store; cc = scan_getc(&sc); } if (i==0) { scan_ungetc(&sc); goto done; /* return cnt */ } if (*p != 'c') { /* nul-terminate the stored string */ *b = 0; } cnt += store; goto nextfmt; } if (p-spec_s < 12) { /* o,u,p,x,X,i,d - (un)signed integer */ if (*p == 'p') { /* assume pointer same size as int or long. */ lval = (sizeof(char *) == sizeof(long)); } usflag = ((p-spec_s) < 10); /* (1)0 if (un)signed */ base = radix[(int)(p-spec_s) - 5]; b = buf; if (sc.width <= 0) { goto done; } cc = scan_getc(&sc); if ((cc == '+') || (cc == '-')) { /* Handle leading sign.*/ *b++ = cc; cc = scan_getc(&sc); } if (cc == '0') { /* Possibly set base and handle prefix. */ if ((base == 0) || (base == 16)) { cc = scan_getc(&sc); if ((cc == 'x') || (cc == 'X')) { /* We're committed to base 16 now. */ base = 16; cc = scan_getc(&sc); } else { /* oops... back up */ scan_ungetc(&sc); cc = '0'; if (base == 0) { base = 8; } } } } if (base == 0) { /* Default to base 10 */ base = 10; } /* At this point, we're ready to start reading digits. */ if (cc == '0') { *b++ = cc; /* Store first leading 0 */ do { /* but ignore others. */ cc = scan_getc(&sc); } while (cc == '0'); } while (valid_digit(cc,base)) { /* Now for nonzero digits.*/ if (b - buf < MAX_DIGITS) { *b++ = cc; } cc = scan_getc(&sc); } *b = 0; /* null-terminate */ if ((b == buf) || (*--b == '+') || (*b == '-')) { scan_ungetc(&sc); goto done; /* No digits! */ } if (store) { if (*buf == '-') { usflag = 0; } uv = STRTO_L_(buf, NULL, base, usflag); vp = va_arg(ap, void *); switch (lval) { case 2: /* If no long long, treat as long . */ #ifdef INCLUDE_LONG_LONG *((unsigned long long *)vp) = uv; break; #endif case 1: #if ULONG_MAX == UINT_MAX case 0: /* int and long int are the same */ #endif #ifdef INCLUDE_LONG_LONG if (usflag) { if (uv > ULONG_MAX) { uv = ULONG_MAX; } } else if (((V_TYPE)uv) > LONG_MAX) { uv = LONG_MAX; } else if (((V_TYPE)uv) < LONG_MIN) { uv = (UV_TYPE) LONG_MIN; } #endif *((unsigned long *)vp) = (unsigned long)uv; break; #if ULONG_MAX != UINT_MAX case 0: /* int and long int are different */ if (usflag) { if (uv > UINT_MAX) { uv = UINT_MAX; } } else if (((V_TYPE)uv) > INT_MAX) { uv = INT_MAX; } else if (((V_TYPE)uv) < INT_MIN) { uv = (UV_TYPE) INT_MIN; } *((unsigned int *)vp) = (unsigned int)uv; break; #endif case -1: if (usflag) { if (uv > USHRT_MAX) { uv = USHRT_MAX; } } else if (((V_TYPE)uv) > SHRT_MAX) { uv = SHRT_MAX; } else if (((V_TYPE)uv) < SHRT_MIN) { uv = (UV_TYPE) SHRT_MIN; } *((unsigned short *)vp) = (unsigned short)uv; break; case -2: if (usflag) { if (uv > UCHAR_MAX) { uv = UCHAR_MAX; } } else if (((V_TYPE)uv) > CHAR_MAX) { uv = CHAR_MAX; } else if (((V_TYPE)uv) < CHAR_MIN) { uv = (UV_TYPE) CHAR_MIN; } *((unsigned char *)vp) = (unsigned char) uv; break; default: assert(0); } ++cnt; } goto nextfmt; } #ifdef INCLUDE_FLOAT else { /* floating point */ if (sc.width <= 0) {
int isspace( int c ) { return __isspace(c); }
void PluginClass::GetOpenPluginInfo(struct OpenPluginInfo *Info) { Info->StructSize=sizeof(*Info); Info->Flags=OPIF_USEFILTER|OPIF_USESORTGROUPS|OPIF_USEHIGHLIGHTING| OPIF_ADDDOTS|OPIF_COMPAREFATTIME; Info->HostFile=ArcName; Info->CurDir=CurDir; if (bGOPIFirstCall) ArcPlugin->GetFormatName(ArcPluginNumber,ArcPluginType,FormatName,DefExt); char NameTitle[NM]; lstrcpyn(NameTitle,FSF.PointToName(ArcName),sizeof(NameTitle)); { struct PanelInfo PInfo; if(::Info.Control((HANDLE)this,FCTL_GETPANELSHORTINFO,&PInfo)) { //TruncStr FSF.TruncPathStr(NameTitle,(PInfo.PanelRect.right-PInfo.PanelRect.left+1-(lstrlen(FormatName)+3+4))); } } FSF.sprintf(Title," %s:%s%s%s ",FormatName,NameTitle, *CurDir ? "\\" : "", *CurDir ? CurDir : ""); Info->PanelTitle=Title; if (bGOPIFirstCall || FarLangChanged()) { FSF.sprintf(Format,GetMsg(MArcFormat),FormatName); memset(InfoLines,0,sizeof(InfoLines)); FSF.sprintf(InfoLines[0].Text,GetMsg(MInfoTitle),FSF.PointToName(ArcName)); InfoLines[0].Separator=TRUE; FSF.sprintf(InfoLines[1].Text,GetMsg(MInfoArchive)); lstrcpy(InfoLines[1].Data,FormatName); if (ItemsInfo.UnpVer!=0) FSF.sprintf(InfoLines[1].Data+lstrlen(InfoLines[1].Data)," %d.%d", ItemsInfo.UnpVer/256,ItemsInfo.UnpVer%256); if (*ItemsInfo.HostOS) FSF.sprintf(InfoLines[1].Data+lstrlen(InfoLines[1].Data),"/%s",ItemsInfo.HostOS); lstrcpy(InfoLines[2].Text,GetMsg(MInfoArcType)); if (ItemsInfo.Solid) lstrcpy(InfoLines[2].Data,GetMsg(MInfoSolid)); if (CurArcInfo.SFXSize) { if (*InfoLines[2].Data) lstrcat(InfoLines[2].Data," "); lstrcat(InfoLines[2].Data,GetMsg(MInfoSFX)); } if (CurArcInfo.Flags & AF_HDRENCRYPTED) { if (*InfoLines[2].Data) lstrcat(InfoLines[2].Data," "); lstrcat(InfoLines[2].Data,GetMsg(MInfoHdrEncrypted)); } if (CurArcInfo.Volume) { if (*InfoLines[2].Data) lstrcat(InfoLines[2].Data," "); lstrcat(InfoLines[2].Data,GetMsg(MInfoVolume)); } if (*InfoLines[2].Data==0) lstrcpy(InfoLines[2].Data,GetMsg(MInfoNormal)); lstrcpy(InfoLines[3].Text,GetMsg(MInfoArcComment)); lstrcpy(InfoLines[3].Data,CurArcInfo.Comment ? GetMsg(MInfoPresent):GetMsg(MInfoAbsent)); lstrcpy(InfoLines[4].Text,GetMsg(MInfoFileComments)); lstrcpy(InfoLines[4].Data,ItemsInfo.Comment ? GetMsg(MInfoPresent):GetMsg(MInfoAbsent)); lstrcpy(InfoLines[5].Text,GetMsg(MInfoPasswords)); lstrcpy(InfoLines[5].Data,ItemsInfo.Encrypted ? GetMsg(MInfoPresent):GetMsg(MInfoAbsent)); lstrcpy(InfoLines[6].Text,GetMsg(MInfoRecovery)); lstrcpy(InfoLines[6].Data,CurArcInfo.Recovery ? GetMsg(MInfoPresent):GetMsg(MInfoAbsent)); lstrcpy(InfoLines[7].Text,GetMsg(MInfoLock)); lstrcpy(InfoLines[7].Data,CurArcInfo.Lock ? GetMsg(MInfoPresent):GetMsg(MInfoAbsent)); lstrcpy(InfoLines[8].Text,GetMsg(MInfoAuthVer)); lstrcpy(InfoLines[8].Data,(CurArcInfo.Flags & AF_AVPRESENT) ? GetMsg(MInfoPresent):GetMsg(MInfoAbsent)); lstrcpy(InfoLines[9].Text,GetMsg(MInfoDict)); if (ItemsInfo.DictSize==0) lstrcpy(InfoLines[9].Data,"???"); else FSF.sprintf(InfoLines[9].Data,"%d %s",ItemsInfo.DictSize,GetMsg(MInfoDictKb)); lstrcpy(InfoLines[10].Text,GetMsg(MInfoChapters)); if(CurArcInfo.Chapters) //FSF.sprintf(InfoLines[10].Data,"%d/%d",ItemsInfo.Chapter,CurArcInfo.Chapters); FSF.sprintf(InfoLines[10].Data,"%d",CurArcInfo.Chapters); else lstrcpy(InfoLines[10].Data,GetMsg(MInfoAbsent)); lstrcpy(InfoLines[11].Text,GetMsg(MInfoTotalFiles)); FSF.sprintf(InfoLines[11].Data,"%d",ArcDataCount); lstrcpy(InfoLines[12].Text,GetMsg(MInfoTotalSize)); InsertCommas(TotalSize,InfoLines[12].Data); lstrcpy(InfoLines[13].Text,GetMsg(MInfoPackedSize)); InsertCommas(PackedSize,InfoLines[13].Data); lstrcpy(InfoLines[14].Text,GetMsg(MInfoRatio)); FSF.sprintf(InfoLines[14].Data,"%d%%",ToPercent(PackedSize,TotalSize)); memset(&KeyBar,0,sizeof(KeyBar)); KeyBar.ShiftTitles[1-1]=(char*)""; KeyBar.AltTitles[6-1]=(char*)GetMsg(MAltF6); KeyBar.AltShiftTitles[9-1]=(char*)GetMsg(MAltShiftF9); } Info->Format=Format; Info->KeyBar=&KeyBar; Info->InfoLines=InfoLines; Info->InfoLinesNumber=ARRAYSIZE(InfoLines); lstrcpy(DescrFilesString,Opt.DescriptionNames); size_t DescrFilesNumber=0; char *NamePtr=DescrFilesString; while (DescrFilesNumber<ARRAYSIZE(DescrFiles)) { while (__isspace(*NamePtr)) NamePtr++; if (*NamePtr==0) break; DescrFiles[DescrFilesNumber++]=NamePtr; if ((NamePtr=strchr(NamePtr,','))==NULL) break; *(NamePtr++)=0; } Info->DescrFiles=DescrFiles; if (!Opt.ReadDescriptions || DizPresent) Info->DescrFilesNumber=0; else Info->DescrFilesNumber=(int)DescrFilesNumber; bGOPIFirstCall = false; }
void dynamic_parse(void *data, pattern_t *pattern, size_t offset) { if(unlikely(!get_flags_dynamic_enable())) return; struct ssn_skb_values * ssv = ( struct ssn_skb_values *)data; //struct l2ct_var_dpi * lvd = &(ssv->ssn->vars_dpi); #if 0 if (unlikely(pattern->pattern_key.dynamic_current_phase - 1 & lvd->ac_state_tbl != pattern->pattern_key.dynamic_current_phase - 1)) { if (i != 4) { D("current_phase[%u], ldv[%p], ac_state_tbl[%u]\n", pattern->pattern_key.dynamic_current_phase,lvd, lvd->ac_state_tbl); aaa =4; } lvd->ac_state_tbl = 0; return; } lvd->ac_state_tbl |= pattern->pattern_key.dynamic_current_phase; if (lvd->ac_state_tbl < pattern->pattern_key.dynamic_need_phase) return; lvd->ac_state_tbl = 0; #endif //get dns or ip + port list //char *sp = ssv->payload + offset + pattern->pattern_len; char *sp = ssv->payload + offset; char *ep = ssv->payload + ssv->payload_len; int pos = 0; uint32_t ip; uint32_t proto_mark; uint16_t port = 0; switch(pattern->pattern_key.dynamic_type) { case 1: { if (pattern->pattern_key.dynamic_port && pattern->pattern_key.dynamic_port != (uint16_t)-1) { if(pattern->pattern_key.dynamic_dir && pattern->pattern_key.dynamic_port != ssv->ssn->sess_key.port_dst) { return; } if(0 == pattern->pattern_key.dynamic_dir && pattern->pattern_key.dynamic_port != ssv->ssn->sess_key.port_src) { return; } } if (pattern->pattern_key.dynamic_dir) { if (pattern->pattern_key.dynamic_port == (uint16_t)-1) { study_cache_try_get(ssv->ssn->sess_key.ip_dst, ssv->dport, ssv->ssn->proto_mark, 0, DYNAMIC_TIMEO); #ifdef DYNAMIC_DEBUG LOG("pattern[%s]add ip [%u]and port [%u.%u.%u.%u:%u] proto[%u] dynamic_indirect[%d]to study cache, common type, \n", pattern->pattern_name, ssv->ssn->sess_key.ip_dst, IPQUADS(ssv->ssn->sess_key.ip_dst), ntohs(ssv->dport), ssv->ssn->proto_mark,pattern->pattern_key.dynamic_indirect); #endif } else { study_cache_try_get(ssv->ssn->sess_key.ip_dst, pattern->pattern_key.dynamic_port, ssv->ssn->proto_mark, 0, DYNAMIC_TIMEO); #ifdef DYNAMIC_DEBUG LOG("pattern[%s]add ip [%u]and port [%u.%u.%u.%u:%u] proto[%u] dynamic_indirect[%d]to study cache, common type, \n", pattern->pattern_name, ssv->ssn->sess_key.ip_dst, IPQUADS(ssv->ssn->sess_key.ip_dst), ntohs(pattern->pattern_key.dynamic_port), ssv->ssn->proto_mark,pattern->pattern_key.dynamic_indirect); #endif } } else { if (pattern->pattern_key.dynamic_port == (uint16_t)-1) { study_cache_try_get(ssv->ssn->sess_key.ip_src, ssv->sport, ssv->ssn->proto_mark, 0, 0); #ifdef DYNAMIC_DEBUG LOG("pattern[%s]add ip [%u]and port [%u.%u.%u.%u:%u] proto[%u] dynamic_indirect[%d]to study cache, common type, \n", pattern->pattern_name, ssv->ssn->sess_key.ip_src, IPQUADS(ssv->ssn->sess_key.ip_src), ntohs(ssv->sport), ssv->ssn->proto_mark,pattern->pattern_key.dynamic_indirect); #endif } else { study_cache_try_get(ssv->ssn->sess_key.ip_src, pattern->pattern_key.dynamic_port, ssv->ssn->proto_mark, 0, 0); #ifdef DYNAMIC_DEBUG LOG("pattern[%s]add ip and port [%u.%u.%u.%u:%u] proto[%u] dynamic_indirect[%d]to study cache, common type\n", pattern->pattern_name, IPQUADS(ssv->ssn->sess_key.ip_src), ntohs(pattern->pattern_key.dynamic_port), ssv->ssn->proto_mark,pattern->pattern_key.dynamic_indirect); #endif } } break; } case 2: { //printf("dns type\n"); parse_dns(data, pattern, offset); break; } case 3:// ip:port[10.211.55.88:88] { do{ pos = subhex_in_mainhex(sp, ep - sp, pattern->pattern_key.ip_key, pattern->pattern_key.ip_key_len, 0); if (pos <= 0) return; sp += pos; for(; __isspace(*sp)||*sp == '"'||*sp == ':'; sp++) { if (sp >= ep) return; } ip = ipv4_stonl(sp); if (unlikely(ip == 0xFFFFFFFF)) return; sp += 6; if (pattern->pattern_key.dynamic_port) { port = pattern->pattern_key.dynamic_port; } else { pos = substr_in_mainstr_nocase(sp, 16, ":", 0); if (pos > 0) { sp += pos; port = port_stons(sp); if (port == 65535) { port = 0; } } } if (likely(pattern->pattern_key.dynamic_indirect == 0) ) { if (pattern->pattern_key.dynamic_dir) { study_cache_try_get(ip, port, ssv->ssn->proto_mark, 0, 0); } else { dynamic_cache_try_get(ip, port, ssv->ssn->proto_mark, 0); } #ifdef DYNAMIC_DEBUG LOG("[%s]add ip and port [%u.%u.%u.%u:%u]proto[%u]to dynamic cache isinner[%d]\n",pattern->pattern_name, IPQUADS(ip), ntohs(port), ssv->ssn->proto_mark, ssv->isinner); #endif } else { if ((proto_mark = dns_study_lookup_behavior(ssv->dip, ssv->dport)) > 0) { if (pattern->pattern_key.dynamic_dir) { study_cache_try_get(ip, port, proto_mark, 0, DNS_STUDY_TIMEO); } else { dynamic_cache_try_get(ip, port, proto_mark, 0); } #ifdef DYNAMIC_DEBUG LOG("[%s] dynamic indirect add ip and port [%u.%u.%u.%u:%u]proto[%u]to dynamic cache isinner[%d]\n", pattern->pattern_name, IPQUADS(ip), ntohs(port), proto_mark, ssv->isinner); #endif } else if ((proto_mark = dns_study_lookup_behavior(ssv->sip, ssv->sport)) > 0) { if (pattern->pattern_key.dynamic_dir) { study_cache_try_get(ip, port, proto_mark, 0, DNS_STUDY_TIMEO); } else { dynamic_cache_try_get(ip, port, proto_mark, 0); } #ifdef DYNAMIC_DEBUG LOG("[%s] dynamic indirect add ip and port [%u.%u.%u.%u:%u]proto[%u]to dynamic cache isinner[%d]\n",pattern->pattern_name, IPQUADS(ip), ntohs(port), proto_mark, ssv->isinner); #endif } } } while (pattern->pattern_key.mult_iplist && sp < ep); // lvd->is_dynamic = 1; break; } case 4://such as: "ip":"111.161.80.157","port":1935, { do{ pos = subhex_in_mainhex(sp, ep - sp, pattern->pattern_key.ip_key, pattern->pattern_key.ip_key_len, 0); if (pos <= 0) return; sp += pos; for(; __isspace(*sp)||*sp == '"'||*sp == ':'; sp++) { if (sp >= ep) return; } ip = ipv4_stonl(sp); if (unlikely(ip == 0xFFFFFFFF)) return; sp += 6; pos = subhex_in_mainhex(sp, ep - sp, pattern->pattern_key.port_key, pattern->pattern_key.port_key_len, 0); if (pos <= 0) return; sp += pos; for(; __isspace(*sp)||*sp == '"'||*sp == ':'; sp++) { if (sp >= ep) return; } port = port_stons(sp); if (likely(pattern->pattern_key.dynamic_indirect == 0) ) { if (pattern->pattern_key.dynamic_dir) { study_cache_try_get(ip, port, ssv->ssn->proto_mark, 0, 0); } else { dynamic_cache_try_get(ip, port, ssv->ssn->proto_mark, 0); } #ifdef DYNAMIC_DEBUG LOG("[%s]add ip and port [%u.%u.%u.%u:%u]proto[%u]to dynamic cache isinner[%d]\n", pattern->pattern_name, IPQUADS(ip), ntohs(port), ssv->ssn->proto_mark, ssv->isinner); #endif } else { if ((proto_mark = dns_study_lookup_behavior(ssv->dip, ssv->dport)) > 0) { if (pattern->pattern_key.dynamic_dir) { study_cache_try_get(ip, port, proto_mark, 0, DNS_STUDY_TIMEO); } else { dynamic_cache_try_get(ip, port, proto_mark, 0); } #ifdef DYNAMIC_DEBUG LOG("[%s] dynamic indirect add ip and port [%u.%u.%u.%u:%u]proto[%u]to dynamic cache isinner[%d]\n", pattern->pattern_name, IPQUADS(ip), ntohs(port), proto_mark, ssv->isinner); #endif } else if ((proto_mark = dns_study_lookup_behavior(ssv->sip, ssv->sport)) > 0) { if (pattern->pattern_key.dynamic_dir) { study_cache_try_get(ip, port, proto_mark, 0, DNS_STUDY_TIMEO); } else { dynamic_cache_try_get(ip, port, proto_mark, 0); } #ifdef DYNAMIC_DEBUG LOG("[%s] dynamic indirect add ip and port [%u.%u.%u.%u:%u]proto[%u]to dynamic cache isinner[%d]\n", pattern->pattern_name, IPQUADS(ip), ntohs(port), proto_mark, ssv->isinner); #endif } } } while (pattern->pattern_key.mult_iplist && sp < ep); // lvd->is_dynamic = 1; break; } case 5: { do{ for(; __isspace(*sp)||*sp == '"'||*sp == ':'; sp++) { if (sp >= ep) return; } ip = ipv4_stonl(sp); if (unlikely(ip == 0xFFFFFFFF)) return; sp += 6; if (pattern->pattern_key.dynamic_port) { port = pattern->pattern_key.dynamic_port; } else { pos = subhex_in_mainhex(sp, 16, pattern->pattern_key.port_key,pattern->pattern_key.port_key_len, 0); if (pos > 0) { sp += pos; port = port_stons(sp); if (port == 65535) { port = 0; } } } if (likely(pattern->pattern_key.dynamic_indirect == 0) ) { if (pattern->pattern_key.dynamic_dir) { study_cache_try_get(ip, port, ssv->ssn->proto_mark, 0, 0); } else { dynamic_cache_try_get(ip, port, ssv->ssn->proto_mark, 0); } #ifdef DYNAMIC_DEBUG LOG("[%s]add ip and port [%u.%u.%u.%u:%u]proto[%u]to dynamic cache isinner[%d]\n", pattern->pattern_name, IPQUADS(ip), ntohs(port), ssv->ssn->proto_mark, ssv->isinner); #endif } else { if ((proto_mark = dns_study_lookup_behavior(ssv->dip, ssv->dport)) > 0) { if (pattern->pattern_key.dynamic_dir) { study_cache_try_get(ip, port, proto_mark, 0, DNS_STUDY_TIMEO); } else { dynamic_cache_try_get(ip, port, proto_mark, 0); } #ifdef DYNAMIC_DEBUG LOG("[%s] dynamic indirect add ip and port [%u.%u.%u.%u:%u]proto[%u]to dynamic cache isinner[%d]\n", pattern->pattern_name, IPQUADS(ip), ntohs(port), proto_mark, ssv->isinner); #endif } else if ((proto_mark = dns_study_lookup_behavior(ssv->sip, ssv->sport)) > 0) { if (pattern->pattern_key.dynamic_dir) { study_cache_try_get(ip, port, proto_mark, 0, DNS_STUDY_TIMEO); } else { dynamic_cache_try_get(ip, port, proto_mark, 0); } #ifdef DYNAMIC_DEBUG LOG("[%s] dynamic indirect add ip and port [%u.%u.%u.%u:%u]proto[%u]to dynamic cache isinner[%d]\n", pattern->pattern_name, IPQUADS(ip), ntohs(port), proto_mark, ssv->isinner); #endif } } } while (pattern->pattern_key.mult_iplist && sp < ep); // lvd->is_dynamic = 1; break; } #if 0 case 5://such as: ch1.dnf.qq.com, { do{ for(; __isspace(*sp); sp++) { if (sp >= ep) return; } pos = substr_in_mainstr_nocase(sp, ep - sp, pattern->port_key, 0); //pos = substr_in_mainstr_nocase(sp, 16, ":", 0); if (pos > 0) { strncopy(domain, sp, pos - strlen(pattern->port_key)); sp += pos; port = simple_strtol(sp, NULL, 0); domain_cache_try_get(domain, ssv->ssn->proto_mark); printk("---port=%u\n", port); } // else { // port = pattern->dynamic_port; // } DEG("add ip and port [%u.%u.%u.%u:%u]proto[%u]to dynamic cache\n", IPQUADS(ip), ntohs(port), ssv->ssn->proto_mark); } while (pattern->mult_iplist && sp < ep); lvd->is_dynamic = 1; break; } #endif default: break; } }