]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
radix: update HTP config lookup logic
authorVictor Julien <victor@inliniac.net>
Fri, 20 Dec 2013 13:32:33 +0000 (14:32 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 7 Feb 2014 16:16:15 +0000 (17:16 +0100)
The HTP config tree is a radix. The lookups are updated to the new API.
The return of user_data is treated as a succesful lookup, instead of
the node itself.

src/app-layer-htp.c

index dfb02047d2f846ce664b2ea1b45ebfa0fbe7073f..d2c0a099ad4f3d13d2c18d89ee2fc5a64c477742 100644 (file)
@@ -656,27 +656,25 @@ static int HTPHandleRequestData(Flow *f, void *htp_state,
     if (NULL == hstate->conn) {
         HTPCfgRec *htp_cfg_rec = &cfglist;
         htp_cfg_t *htp = cfglist.cfg; /* Default to the global HTP config */
-        SCRadixNode *cfgnode = NULL;
+        void *user_data = NULL;
 
         if (FLOW_IS_IPV4(f)) {
             SCLogDebug("Looking up HTP config for ipv4 %08x", *GET_IPV4_DST_ADDR_PTR(f));
-            cfgnode = SCRadixFindKeyIPV4BestMatch((uint8_t *)GET_IPV4_DST_ADDR_PTR(f), cfgtree);
+            (void)SCRadixFindKeyIPV4BestMatch((uint8_t *)GET_IPV4_DST_ADDR_PTR(f), cfgtree, &user_data);
         }
         else if (FLOW_IS_IPV6(f)) {
             SCLogDebug("Looking up HTP config for ipv6");
-            cfgnode = SCRadixFindKeyIPV6BestMatch((uint8_t *)GET_IPV6_DST_ADDR(f), cfgtree);
+            (void)SCRadixFindKeyIPV6BestMatch((uint8_t *)GET_IPV6_DST_ADDR(f), cfgtree, &user_data);
         }
         else {
             SCLogError(SC_ERR_INVALID_ARGUMENT, "unknown address family, bug!");
             goto error;
         }
 
-        if (cfgnode != NULL) {
-            htp_cfg_rec = SC_RADIX_NODE_USERDATA(cfgnode, HTPCfgRec);
-            if (htp_cfg_rec != NULL) {
-                htp = htp_cfg_rec->cfg;
-                SCLogDebug("LIBHTP using config: %p", htp);
-            }
+        if (user_data != NULL) {
+            htp_cfg_rec = user_data;
+            htp = htp_cfg_rec->cfg;
+            SCLogDebug("LIBHTP using config: %p", htp);
         } else {
             SCLogDebug("Using default HTP config: %p", htp);
         }
@@ -4116,20 +4114,18 @@ libhtp:\n\
         goto end;
     }
 
-    SCRadixNode *cfgnode = NULL;
     htp_cfg_t *htp = cfglist.cfg;
     uint8_t buf[128];
     const char *addr;
+    void *user_data = NULL;
 
     addr = "192.168.10.42";
     if (inet_pton(AF_INET, addr, buf) == 1) {
-        cfgnode = SCRadixFindKeyIPV4BestMatch(buf, cfgtree);
-        if (cfgnode != NULL) {
-            HTPCfgRec *htp_cfg_rec = SC_RADIX_NODE_USERDATA(cfgnode, HTPCfgRec);
-            if (htp_cfg_rec != NULL) {
-                htp = htp_cfg_rec->cfg;
-                SCLogDebug("LIBHTP using config: %p", htp);
-            }
+        (void)SCRadixFindKeyIPV4BestMatch(buf, cfgtree, &user_data);
+        if (user_data != NULL) {
+            HTPCfgRec *htp_cfg_rec = user_data;
+            htp = htp_cfg_rec->cfg;
+            SCLogDebug("LIBHTP using config: %p", htp);
         }
         if (htp == NULL) {
             printf("Could not get config for: %s\n", addr);
@@ -4141,15 +4137,14 @@ libhtp:\n\
         goto end;
     }
 
+    user_data = NULL;
     addr = "::1";
     if (inet_pton(AF_INET6, addr, buf) == 1) {
-        cfgnode = SCRadixFindKeyIPV6BestMatch(buf, cfgtree);
-        if (cfgnode != NULL) {
-            HTPCfgRec *htp_cfg_rec = SC_RADIX_NODE_USERDATA(cfgnode, HTPCfgRec);
-            if (htp_cfg_rec != NULL) {
-                htp = htp_cfg_rec->cfg;
-                SCLogDebug("LIBHTP using config: %p", htp);
-            }
+        (void)SCRadixFindKeyIPV6BestMatch(buf, cfgtree, &user_data);
+        if (user_data != NULL) {
+            HTPCfgRec *htp_cfg_rec = user_data;
+            htp = htp_cfg_rec->cfg;
+            SCLogDebug("LIBHTP using config: %p", htp);
         }
         if (htp == NULL) {
             printf("Could not get config for: %s\n", addr);
@@ -4224,16 +4219,14 @@ libhtp:\n\
     f->protoctx = &ssn;
     f->proto = IPPROTO_TCP;
 
-    SCRadixNode *cfgnode = NULL;
     htp_cfg_t *htp = cfglist.cfg;
 
-    cfgnode = SCRadixFindKeyIPV4BestMatch((uint8_t *)f->dst.addr_data32, cfgtree);
-    if (cfgnode != NULL) {
-        HTPCfgRec *htp_cfg_rec = SC_RADIX_NODE_USERDATA(cfgnode, HTPCfgRec);
-        if (htp_cfg_rec != NULL) {
-            htp = htp_cfg_rec->cfg;
-            SCLogDebug("LIBHTP using config: %p", htp);
-        }
+    void *user_data = NULL;
+    (void)SCRadixFindKeyIPV4BestMatch((uint8_t *)f->dst.addr_data32, cfgtree, &user_data);
+    if (user_data != NULL) {
+        HTPCfgRec *htp_cfg_rec = user_data;
+        htp = htp_cfg_rec->cfg;
+        SCLogDebug("LIBHTP using config: %p", htp);
     }
     if (htp == NULL) {
         printf("Could not get config for: %s\n", addr);