]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Openbsd: Fix some warning related to inline usage.
authorEric Leblond <eric@regit.org>
Fri, 11 May 2012 17:25:55 +0000 (19:25 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 16 May 2012 09:24:33 +0000 (11:24 +0200)
gcc on OpenBSD does not support C99 inline functions. This patch
modify the build system to handle this. It also change the order
of declaration of some functions to avoid to use them before
declaring them as inline.

configure.in
src/decode.c
src/util-mpm-b3g.c
src/util-mpm-wumanber.c

index 8c5248479d78cb9ecf7b4d5be956e1afc9874a51..2516c277e1e70770168df925e2ca5dfdb5d55f72 100644 (file)
@@ -133,7 +133,7 @@ AC_INIT(configure.in)
                     LDFLAGS="${LDFLAGS} -L/usr/local/lib -L/usr/local/lib/libnet11"
                     ;;
            *-*-openbsd*)
-                    CFLAGS="${CFLAGS} -D__OpenBSD__"
+                    CFLAGS="${CFLAGS} -D__OpenBSD__ -fgnu89-inline"
                     CPPFLAGS="${CPPFLAGS} -I/usr/local/include -I/usr/local/include/libnet-1.1"
                     LDFLAGS="${LDFLAGS} -L/usr/local/lib -I/usr/local/lib/libnet-1.1"
                     ;;
index 95b1c3d960e04a322f22b1eb886c064617f79a2f..342dd4b7bbaeb3e20b4d3e97c9b4d46fa8abba6b 100644 (file)
@@ -124,6 +124,65 @@ Packet *PacketGetFromQueueOrAlloc(void)
     return p;
 }
 
+/**
+ *  \brief Copy data to Packet payload at given offset
+ *
+ * This function copies data/payload to a Packet. It uses the
+ * space allocated at Packet creation (pointed by Packet::pkt)
+ * or allocate some memory (pointed by Packet::ext_pkt) if the
+ * data size is to big to fit in initial space (of size
+ * default_packet_size).
+ *
+ *  \param Pointer to the Packet to modify
+ *  \param Offset of the copy relatively to payload of Packet
+ *  \param Pointer to the data to copy
+ *  \param Length of the data to copy
+ */
+inline int PacketCopyDataOffset(Packet *p, int offset, uint8_t *data, int datalen)
+{
+    if (offset + datalen > MAX_PAYLOAD_SIZE) {
+        /* too big */
+        return -1;
+    }
+
+    /* Do we have already an packet with allocated data */
+    if (! p->ext_pkt) {
+        if (offset + datalen <= (int)default_packet_size) {
+            /* data will fit in memory allocated with packet */
+            memcpy(p->pkt + offset, data, datalen);
+        } else {
+            /* here we need a dynamic allocation */
+            p->ext_pkt = SCMalloc(MAX_PAYLOAD_SIZE);
+            if (p->ext_pkt == NULL) {
+                SET_PKT_LEN(p, 0);
+                return -1;
+            }
+            /* copy initial data */
+            memcpy(p->ext_pkt, GET_PKT_DIRECT_DATA(p), GET_PKT_DIRECT_MAX_SIZE(p));
+            /* copy data as asked */
+            memcpy(p->ext_pkt + offset, data, datalen);
+        }
+    } else {
+        memcpy(p->ext_pkt + offset, data, datalen);
+    }
+    return 0;
+}
+
+/**
+ *  \brief Copy data to Packet payload and set packet length
+ *
+ *  \param Pointer to the Packet to modify
+ *  \param Pointer to the data to copy
+ *  \param Length of the data to copy
+ */
+inline int PacketCopyData(Packet *p, uint8_t *pktdata, int pktlen)
+{
+    SET_PKT_LEN(p, (size_t)pktlen);
+    return PacketCopyDataOffset(p, 0, pktdata, pktlen);
+}
+
+
+
 /**
  *  \brief Setup a pseudo packet (tunnel)
  *
@@ -341,63 +400,6 @@ DecodeThreadVars *DecodeThreadVarsAlloc() {
     return dtv;
 }
 
-/**
- *  \brief Copy data to Packet payload at given offset
- *
- * This function copies data/payload to a Packet. It uses the
- * space allocated at Packet creation (pointed by Packet::pkt)
- * or allocate some memory (pointed by Packet::ext_pkt) if the
- * data size is to big to fit in initial space (of size
- * default_packet_size).
- *
- *  \param Pointer to the Packet to modify
- *  \param Offset of the copy relatively to payload of Packet
- *  \param Pointer to the data to copy
- *  \param Length of the data to copy
- */
-inline int PacketCopyDataOffset(Packet *p, int offset, uint8_t *data, int datalen)
-{
-    if (offset + datalen > MAX_PAYLOAD_SIZE) {
-        /* too big */
-        return -1;
-    }
-
-    /* Do we have already an packet with allocated data */
-    if (! p->ext_pkt) {
-        if (offset + datalen <= (int)default_packet_size) {
-            /* data will fit in memory allocated with packet */
-            memcpy(p->pkt + offset, data, datalen);
-        } else {
-            /* here we need a dynamic allocation */
-            p->ext_pkt = SCMalloc(MAX_PAYLOAD_SIZE);
-            if (p->ext_pkt == NULL) {
-                SET_PKT_LEN(p, 0);
-                return -1;
-            }
-            /* copy initial data */
-            memcpy(p->ext_pkt, GET_PKT_DIRECT_DATA(p), GET_PKT_DIRECT_MAX_SIZE(p));
-            /* copy data as asked */
-            memcpy(p->ext_pkt + offset, data, datalen);
-        }
-    } else {
-        memcpy(p->ext_pkt + offset, data, datalen);
-    }
-    return 0;
-}
-
-/**
- *  \brief Copy data to Packet payload and set packet length
- *
- *  \param Pointer to the Packet to modify
- *  \param Pointer to the data to copy
- *  \param Length of the data to copy
- */
-inline int PacketCopyData(Packet *p, uint8_t *pktdata, int pktlen)
-{
-    SET_PKT_LEN(p, (size_t)pktlen);
-    return PacketCopyDataOffset(p, 0, pktdata, pktlen);
-}
-
 
 /**
  * \brief Set data for Packet and set length when zeo copy is used
index 5154c459ac91e300a7efde6c72dd29598fdc285d..4a45f5bac3a59aba155aa3224015d9cd1e8588f6 100644 (file)
@@ -72,23 +72,6 @@ void B3gPrintInfo(MpmCtx *);
 void B3gPrintSearchStats(MpmThreadCtx *);
 void B3gRegisterTests(void);
 
-void MpmB3gRegister (void) {
-    mpm_table[MPM_B3G].name = "b3g";
-    mpm_table[MPM_B3G].max_pattern_length = B3G_WORD_SIZE;
-    mpm_table[MPM_B3G].InitCtx = B3gInitCtx;
-    mpm_table[MPM_B3G].InitThreadCtx = B3gThreadInitCtx;
-    mpm_table[MPM_B3G].DestroyCtx = B3gDestroyCtx;
-    mpm_table[MPM_B3G].DestroyThreadCtx = B3gThreadDestroyCtx;
-    mpm_table[MPM_B3G].AddPattern = B3gAddPatternCS;
-    mpm_table[MPM_B3G].AddPatternNocase = B3gAddPatternCI;
-    mpm_table[MPM_B3G].Prepare = B3gPreparePatterns;
-    mpm_table[MPM_B3G].Search = B3gSearchWrap;
-    mpm_table[MPM_B3G].Cleanup = NULL;
-    mpm_table[MPM_B3G].PrintCtx = B3gPrintInfo;
-    mpm_table[MPM_B3G].PrintThreadCtx = B3gPrintSearchStats;
-    mpm_table[MPM_B3G].RegisterUnittests = B3gRegisterTests;
-}
-
 /** \todo XXX Unused??? */
 #if 0
 static void prt (uint8_t *buf, uint16_t buflen) {
@@ -1221,6 +1204,23 @@ uint32_t B3gSearch1(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, PatternMatche
     return cnt;
 }
 
+void MpmB3gRegister (void) {
+    mpm_table[MPM_B3G].name = "b3g";
+    mpm_table[MPM_B3G].max_pattern_length = B3G_WORD_SIZE;
+    mpm_table[MPM_B3G].InitCtx = B3gInitCtx;
+    mpm_table[MPM_B3G].InitThreadCtx = B3gThreadInitCtx;
+    mpm_table[MPM_B3G].DestroyCtx = B3gDestroyCtx;
+    mpm_table[MPM_B3G].DestroyThreadCtx = B3gThreadDestroyCtx;
+    mpm_table[MPM_B3G].AddPattern = B3gAddPatternCS;
+    mpm_table[MPM_B3G].AddPatternNocase = B3gAddPatternCI;
+    mpm_table[MPM_B3G].Prepare = B3gPreparePatterns;
+    mpm_table[MPM_B3G].Search = B3gSearchWrap;
+    mpm_table[MPM_B3G].Cleanup = NULL;
+    mpm_table[MPM_B3G].PrintCtx = B3gPrintInfo;
+    mpm_table[MPM_B3G].PrintThreadCtx = B3gPrintSearchStats;
+    mpm_table[MPM_B3G].RegisterUnittests = B3gRegisterTests;
+}
+
 /*
  * TESTS
  */
index 17197bb544b286f33cbf0d02c10f4e4193617465..5b19c82c458d52e3076f881f3a7c33f312921378 100644 (file)
@@ -89,32 +89,6 @@ static uint8_t lowercasetable[256];
 #define COUNT(counter)
 #endif /* WUMANBER_COUNTERS */
 
-void MpmWuManberRegister (void) {
-    mpm_table[MPM_WUMANBER].name = "wumanber";
-    mpm_table[MPM_WUMANBER].max_pattern_length = 0;
-    mpm_table[MPM_WUMANBER].InitCtx = WmInitCtx;
-    mpm_table[MPM_WUMANBER].InitThreadCtx = WmThreadInitCtx;
-    mpm_table[MPM_WUMANBER].DestroyCtx = WmDestroyCtx;
-    mpm_table[MPM_WUMANBER].DestroyThreadCtx = WmThreadDestroyCtx;
-    mpm_table[MPM_WUMANBER].AddPattern = WmAddPatternCS;
-    mpm_table[MPM_WUMANBER].AddPatternNocase = WmAddPatternCI;
-    mpm_table[MPM_WUMANBER].Prepare = WmPreparePatterns;
-    mpm_table[MPM_WUMANBER].Search = WmSearch;
-    mpm_table[MPM_WUMANBER].Cleanup = NULL;
-    mpm_table[MPM_WUMANBER].PrintCtx = WmPrintInfo;
-    mpm_table[MPM_WUMANBER].PrintThreadCtx = WmPrintSearchStats;
-    mpm_table[MPM_WUMANBER].RegisterUnittests = WmRegisterTests;
-
-    /* create table for O(1) lowercase conversion lookup */
-    uint8_t c = 0;
-    for ( ; c < 255; c++) {
-       if (c >= 'A' && c <= 'Z')
-           lowercasetable[c] = (c + ('a' - 'A'));
-       else
-           lowercasetable[c] = c;
-    }
-}
-
 void prt (uint8_t *buf, uint16_t buflen) {
     uint16_t i;
 
@@ -1450,6 +1424,32 @@ void WmThreadDestroyCtx(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx) {
     }
 }
 
+void MpmWuManberRegister (void) {
+    mpm_table[MPM_WUMANBER].name = "wumanber";
+    mpm_table[MPM_WUMANBER].max_pattern_length = 0;
+    mpm_table[MPM_WUMANBER].InitCtx = WmInitCtx;
+    mpm_table[MPM_WUMANBER].InitThreadCtx = WmThreadInitCtx;
+    mpm_table[MPM_WUMANBER].DestroyCtx = WmDestroyCtx;
+    mpm_table[MPM_WUMANBER].DestroyThreadCtx = WmThreadDestroyCtx;
+    mpm_table[MPM_WUMANBER].AddPattern = WmAddPatternCS;
+    mpm_table[MPM_WUMANBER].AddPatternNocase = WmAddPatternCI;
+    mpm_table[MPM_WUMANBER].Prepare = WmPreparePatterns;
+    mpm_table[MPM_WUMANBER].Search = WmSearch;
+    mpm_table[MPM_WUMANBER].Cleanup = NULL;
+    mpm_table[MPM_WUMANBER].PrintCtx = WmPrintInfo;
+    mpm_table[MPM_WUMANBER].PrintThreadCtx = WmPrintSearchStats;
+    mpm_table[MPM_WUMANBER].RegisterUnittests = WmRegisterTests;
+
+    /* create table for O(1) lowercase conversion lookup */
+    uint8_t c = 0;
+    for ( ; c < 255; c++) {
+       if (c >= 'A' && c <= 'Z')
+           lowercasetable[c] = (c + ('a' - 'A'));
+       else
+           lowercasetable[c] = c;
+    }
+}
+
 /*
  * ONLY TESTS BELOW THIS COMMENT
  */