summaryrefslogtreecommitdiffstats
path: root/src/core/object.c
blob: 33190dd3fde660c15eb124abd419d55aa88fe8b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * Copyright (c) 2018-2024 OARC, Inc.
 * All rights reserved.
 *
 * This file is part of dnsjit.
 *
 * dnsjit is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * dnsjit is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with dnsjit.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "config.h"

#include "core/object.h"
#include "core/assert.h"
#include "core/object/pcap.h"
#include "core/object/ether.h"
#include "core/object/null.h"
#include "core/object/loop.h"
#include "core/object/linuxsll.h"
#include "core/object/ieee802.h"
#include "core/object/gre.h"
#include "core/object/ip.h"
#include "core/object/ip6.h"
#include "core/object/icmp.h"
#include "core/object/icmp6.h"
#include "core/object/udp.h"
#include "core/object/tcp.h"
#include "core/object/payload.h"
#include "core/object/dns.h"

core_object_t* core_object_copy(const core_object_t* self)
{
    glassert_self();

    switch (self->obj_type) {
    case CORE_OBJECT_PCAP:
        return (core_object_t*)core_object_pcap_copy((core_object_pcap_t*)self);
    case CORE_OBJECT_ETHER:
        return (core_object_t*)core_object_ether_copy((core_object_ether_t*)self);
    case CORE_OBJECT_NULL:
        return (core_object_t*)core_object_null_copy((core_object_null_t*)self);
    case CORE_OBJECT_LOOP:
        return (core_object_t*)core_object_loop_copy((core_object_loop_t*)self);
    case CORE_OBJECT_LINUXSLL:
        return (core_object_t*)core_object_linuxsll_copy((core_object_linuxsll_t*)self);
    case CORE_OBJECT_IEEE802:
        return (core_object_t*)core_object_ieee802_copy((core_object_ieee802_t*)self);
    case CORE_OBJECT_GRE:
        return (core_object_t*)core_object_gre_copy((core_object_gre_t*)self);
    case CORE_OBJECT_IP:
        return (core_object_t*)core_object_ip_copy((core_object_ip_t*)self);
    case CORE_OBJECT_IP6:
        return (core_object_t*)core_object_ip6_copy((core_object_ip6_t*)self);
    case CORE_OBJECT_ICMP:
        return (core_object_t*)core_object_icmp_copy((core_object_icmp_t*)self);
    case CORE_OBJECT_ICMP6:
        return (core_object_t*)core_object_icmp6_copy((core_object_icmp6_t*)self);
    case CORE_OBJECT_UDP:
        return (core_object_t*)core_object_udp_copy((core_object_udp_t*)self);
    case CORE_OBJECT_TCP:
        return (core_object_t*)core_object_tcp_copy((core_object_tcp_t*)self);
    case CORE_OBJECT_PAYLOAD:
        return (core_object_t*)core_object_payload_copy((core_object_payload_t*)self);
    case CORE_OBJECT_DNS:
        return (core_object_t*)core_object_dns_copy((core_object_dns_t*)self);
    default:
        glfatal("unknown type %d", self->obj_type);
    }
    return 0;
}

void core_object_free(core_object_t* self)
{
    glassert_self();

    switch (self->obj_type) {
    case CORE_OBJECT_PCAP:
        core_object_pcap_free((core_object_pcap_t*)self);
        break;
    case CORE_OBJECT_ETHER:
        core_object_ether_free((core_object_ether_t*)self);
        break;
    case CORE_OBJECT_NULL:
        core_object_null_free((core_object_null_t*)self);
        break;
    case CORE_OBJECT_LOOP:
        core_object_loop_free((core_object_loop_t*)self);
        break;
    case CORE_OBJECT_LINUXSLL:
        core_object_linuxsll_free((core_object_linuxsll_t*)self);
        break;
    case CORE_OBJECT_IEEE802:
        core_object_ieee802_free((core_object_ieee802_t*)self);
        break;
    case CORE_OBJECT_GRE:
        core_object_gre_free((core_object_gre_t*)self);
        break;
    case CORE_OBJECT_IP:
        core_object_ip_free((core_object_ip_t*)self);
        break;
    case CORE_OBJECT_IP6:
        core_object_ip6_free((core_object_ip6_t*)self);
        break;
    case CORE_OBJECT_ICMP:
        core_object_icmp_free((core_object_icmp_t*)self);
        break;
    case CORE_OBJECT_ICMP6:
        core_object_icmp6_free((core_object_icmp6_t*)self);
        break;
    case CORE_OBJECT_UDP:
        core_object_udp_free((core_object_udp_t*)self);
        break;
    case CORE_OBJECT_TCP:
        core_object_tcp_free((core_object_tcp_t*)self);
        break;
    case CORE_OBJECT_PAYLOAD:
        core_object_payload_free((core_object_payload_t*)self);
        break;
    case CORE_OBJECT_DNS:
        core_object_dns_free((core_object_dns_t*)self);
        break;
    default:
        glfatal("unknown type %d", self->obj_type);
    }
}