Openbsd: Fix some warning related to inline usage.

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.
remotes/origin/master
Eric Leblond 14 years ago committed by Victor Julien
parent aef4835c56
commit 59057e542e

@ -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"
;;

@ -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

@ -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
*/

@ -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
*/

Loading…
Cancel
Save