suricata
datasets-ipv4.c
Go to the documentation of this file.
1
/* Copyright (C) 2022 Open Information Security Foundation
2
*
3
* You can copy, redistribute or modify this Program under the terms of
4
* the GNU General Public License version 2 as published by the Free
5
* Software Foundation.
6
*
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
11
*
12
* You should have received a copy of the GNU General Public License
13
* version 2 along with this program; if not, write to the Free Software
14
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15
* 02110-1301, USA.
16
*/
17
18
/**
19
* \file
20
*
21
* \author Eric Leblond <el@stamus-networks.com>
22
*/
23
24
#include "
suricata-common.h
"
25
#include "
conf.h
"
26
#include "
datasets.h
"
27
#include "
datasets-ipv4.h
"
28
#include "
util-hash-lookup3.h
"
29
#include "
util-thash.h
"
30
#include "
util-print.h
"
31
32
int
IPv4Set
(
void
*
dst
,
void
*
src
)
33
{
34
IPv4Type
*src_s =
src
;
35
IPv4Type
*dst_s =
dst
;
36
memcpy(dst_s->
ipv4
, src_s->
ipv4
,
sizeof
(dst_s->
ipv4
));
37
dst_s->
rep
= src_s->
rep
;
38
return
0;
39
}
40
41
int
IPv4JsonSet
(
void
*
dst
,
void
*
src
)
42
{
43
if
(
IPv4Set
(
dst
,
src
) < 0)
44
return
-1;
45
46
IPv4Type
*src_s =
src
;
47
IPv4Type
*dst_s =
dst
;
48
49
if
(
DatajsonCopyJson
(&dst_s->
json
, &src_s->
json
) < 0)
50
return
-1;
51
52
return
0;
53
}
54
55
bool
IPv4Compare
(
void
*a,
void
*b)
56
{
57
const
IPv4Type
*as = a;
58
const
IPv4Type
*bs = b;
59
60
return
(memcmp(as->
ipv4
, bs->
ipv4
,
sizeof
(as->
ipv4
)) == 0);
61
}
62
63
uint32_t
IPv4Hash
(uint32_t hash_seed,
void
*s)
64
{
65
const
IPv4Type
*
str
= s;
66
return
hashword
((uint32_t *)
str
->ipv4, 1, hash_seed);
67
}
68
69
// data stays in hash
70
void
IPv4Free
(
void
*s)
71
{
72
}
73
74
void
IPv4JsonFree
(
void
*s)
75
{
76
const
IPv4Type
*as = s;
77
if
(as->
json
.
value
) {
78
SCFree
(as->
json
.
value
);
79
}
80
}
81
82
uint32_t
IPv4JsonGetLength
(
void
*s)
83
{
84
const
IPv4Type
*as = s;
85
return
as->
json
.
len
;
86
}
DataJsonType::len
uint16_t len
Definition:
datasets-context-json.h:34
hashword
uint32_t hashword(const uint32_t *k, size_t length, uint32_t initval)
Definition:
util-hash-lookup3.c:172
IPv4JsonSet
int IPv4JsonSet(void *dst, void *src)
Definition:
datasets-ipv4.c:41
IPv4JsonFree
void IPv4JsonFree(void *s)
Definition:
datasets-ipv4.c:74
IPv4Hash
uint32_t IPv4Hash(uint32_t hash_seed, void *s)
Definition:
datasets-ipv4.c:63
datasets.h
IPv4JsonGetLength
uint32_t IPv4JsonGetLength(void *s)
Definition:
datasets-ipv4.c:82
util-print.h
datasets-ipv4.h
IPv4Set
int IPv4Set(void *dst, void *src)
Definition:
datasets-ipv4.c:32
conf.h
IPv4Type::json
DataJsonType json
Definition:
datasets-ipv4.h:34
IPv4Free
void IPv4Free(void *s)
Definition:
datasets-ipv4.c:70
suricata-common.h
util-hash-lookup3.h
IPv4Type
Definition:
datasets-ipv4.h:30
IPv4Compare
bool IPv4Compare(void *a, void *b)
Definition:
datasets-ipv4.c:55
DatajsonCopyJson
int DatajsonCopyJson(DataJsonType *dst, DataJsonType *src)
Definition:
datasets-context-json.c:54
str
#define str(s)
Definition:
suricata-common.h:308
SCFree
#define SCFree(p)
Definition:
util-mem.h:61
src
uint16_t src
Definition:
app-layer-dnp3.h:5
DataJsonType::value
char * value
Definition:
datasets-context-json.h:33
IPv4Type::ipv4
uint8_t ipv4[4]
Definition:
datasets-ipv4.h:31
IPv4Type::rep
DataRepType rep
Definition:
datasets-ipv4.h:33
dst
uint16_t dst
Definition:
app-layer-dnp3.h:4
util-thash.h
src
datasets-ipv4.c
Generated on Mon Jun 30 2025 23:30:27 for suricata by
1.8.18