Skip to content

Commit

Permalink
[unit] Add dummy source for netfilter-conntrack API functions. JB#60770
Browse files Browse the repository at this point in the history
Easier to get various tests to build with a dummy source for the
netfilter-conntrack API functions.
  • Loading branch information
LaakkonenJussi committed Nov 22, 2024
1 parent bd98779 commit 9705212
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 5 deletions.
10 changes: 5 additions & 5 deletions connman/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ if XTABLES
unit_test_firewall_iptables_SOURCES = $(backtrace_sources) src/connman.h \
src/log.c src/inotify.c src/dbus.c src/error.c \
src/inet.c src/iptables-validate.c \
unit/test-firewall-iptables.c
unit/nfct_dummy.c unit/test-firewall-iptables.c
unit_test_firewall_iptables_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ -ldl
endif

Expand Down Expand Up @@ -644,12 +644,12 @@ tools_stats_tool_LDADD = @GLIB_LIBS@

tools_dhcp_test_SOURCES = $(backtrace_sources) src/log.c src/util.c \
$(gdhcp_sources) src/inet.c tools/dhcp-test.c src/shared/arp.c \
src/wakeup_timer.c
src/wakeup_timer.c unit/nfct_dummy.c
tools_dhcp_test_LDADD = @GLIB_LIBS@ -ldl

tools_dhcp_server_test_SOURCES = $(backtrace_sources) src/log.c src/util.c \
$(gdhcp_sources) src/inet.c tools/dhcp-server-test.c src/shared/arp.c \
src/wakeup_timer.c
$(gdhcp_sources) src/inet.c tools/dhcp-server-test.c \
src/shared/arp.c src/wakeup_timer.c unit/nfct_dummy.c
tools_dhcp_server_test_LDADD = @GLIB_LIBS@ -ldl

tools_dbus_test_SOURCES = tools/dbus-test.c
Expand Down Expand Up @@ -685,7 +685,7 @@ tools_iptables_unit_CFLAGS = @DBUS_CFLAGS@ @GLIB_CFLAGS@ @XTABLES_CFLAGS@ \
tools_iptables_unit_SOURCES = $(backtrace_sources) src/log.c src/storage.c \
src/inotify.c src/iptables.c src/nat.c \
src/inet.c src/iptables-validate.c tools/iptables-unit.c \
src/error.c src/dbus.c
src/error.c src/dbus.c unit/nfct_dummy.c
tools_iptables_unit_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ @XTABLES_LIBS@ @LIBIPTC_LIBS@ -ldl

tools_ip6tables_test_SOURCES = $(backtrace_sources) src/log.c \
Expand Down
136 changes: 136 additions & 0 deletions connman/unit/nfct_dummy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* ConnMan netfilter-conntrack dummy functions
*
* Copyright (C) 2024 xxx
*
* Contact: [email protected]
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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.
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <glib.h>
#include <unistd.h>

#include <libnetfilter_conntrack/libnetfilter_conntrack.h>

struct nfct_handle *nfct_open(uint8_t subsys_id, unsigned int subscriptions)
{
return NULL;
}

int nfct_close(struct nfct_handle *cth)
{
g_assert(cth);
return 0;
}

struct nf_conntrack *nfct_new(void)
{
return NULL;
}

void nfct_destroy(struct nf_conntrack *ct)
{
g_assert(ct);
return;
}

int nfct_callback_register(struct nfct_handle *h,
enum nf_conntrack_msg_type type,
int (*cb)(enum nf_conntrack_msg_type type,
struct nf_conntrack *ct,
void *data),
void *data)
{
g_assert(h);
g_assert(cb);

return 0;
}

void nfct_callback_unregister(struct nfct_handle *h)
{
g_assert(h);
}

void nfct_set_attr(struct nf_conntrack *ct,
const enum nf_conntrack_attr type,
const void *value)
{
g_assert(ct);
g_assert(value);
return;
}

void nfct_set_attr_u8(struct nf_conntrack *ct,
const enum nf_conntrack_attr type,
uint8_t value)
{
g_assert(ct);
return;
}

void nfct_set_attr_u16(struct nf_conntrack *ct,
const enum nf_conntrack_attr type,
uint16_t value)
{
g_assert(ct);
return;
}

void nfct_set_attr_u32(struct nf_conntrack *ct,
const enum nf_conntrack_attr type,
uint32_t value)
{
g_assert(ct);
return;
}



const void *nfct_get_attr(const struct nf_conntrack *ct,
const enum nf_conntrack_attr type)
{
g_assert(ct);
return NULL;
}

uint8_t nfct_get_attr_u8(const struct nf_conntrack *ct,
const enum nf_conntrack_attr type)
{
g_assert(ct);
return 0;
}

uint16_t nfct_get_attr_u16(const struct nf_conntrack *ct,
const enum nf_conntrack_attr type)
{
g_assert(ct);
return 0;
}

uint32_t nfct_get_attr_u32(const struct nf_conntrack *ct,
const enum nf_conntrack_attr type)
{
g_assert(ct);
return 0;
}

int nfct_query(struct nfct_handle *h, const enum nf_conntrack_query query,
const void *data)
{
g_assert(h);
return 0;
}

0 comments on commit 9705212

Please sign in to comment.