suricata
datasets-ipv6.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"
28#include "datasets-ipv6.h"
29#include "util-hash-lookup3.h"
30#include "util-thash.h"
31#include "util-print.h"
32
33int IPv6Set(void *dst, void *src)
34{
35 IPv6Type *src_s = src;
36 IPv6Type *dst_s = dst;
37 memcpy(dst_s->ipv6, src_s->ipv6, sizeof(dst_s->ipv6));
38 dst_s->rep = src_s->rep;
39 return 0;
40}
41
42int IPv6JsonSet(void *dst, void *src)
43{
44 if (IPv6Set(dst, src) < 0)
45 return -1;
46
47 IPv6Type *src_s = src;
48 IPv6Type *dst_s = dst;
49
50 if (DatajsonCopyJson(&dst_s->json, &src_s->json) < 0)
51 return -1;
52
53 return 0;
54}
55
56bool IPv6Compare(void *a, void *b)
57{
58 const IPv6Type *as = a;
59 const IPv6Type *bs = b;
60
61 return (memcmp(as->ipv6, bs->ipv6, sizeof(as->ipv6)) == 0);
62}
63
64uint32_t IPv6Hash(uint32_t hash_seed, void *s)
65{
66 const IPv6Type *str = s;
67 return hashword((uint32_t *)str->ipv6, 4, hash_seed);
68}
69
70// data stays in hash
71void IPv6Free(void *s)
72{
73}
74
75void IPv6JsonFree(void *s)
76{
77 const IPv6Type *as = s;
78 if (as->json.value) {
79 SCFree(as->json.value);
80 }
81}
82
83uint32_t IPv6JsonGetLength(void *s)
84{
85 const IPv6Type *as = s;
86 return as->json.len;
87}
uint16_t dst
uint16_t src
int DatajsonCopyJson(DataJsonType *dst, DataJsonType *src)
void IPv6Free(void *s)
int IPv6Set(void *dst, void *src)
void IPv6JsonFree(void *s)
uint32_t IPv6JsonGetLength(void *s)
uint32_t IPv6Hash(uint32_t hash_seed, void *s)
bool IPv6Compare(void *a, void *b)
int IPv6JsonSet(void *dst, void *src)
DataRepType rep
uint8_t ipv6[16]
DataJsonType json
#define str(s)
uint32_t hashword(const uint32_t *k, size_t length, uint32_t initval)
#define SCFree(p)
Definition util-mem.h:61