Skip to content

Commit

Permalink
(conan-io#5312) Add libnetfilter_conntrack/1.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
skannan89 authored Apr 26, 2021
1 parent 811edb7 commit 5e2ee46
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 0 deletions.
4 changes: 4 additions & 0 deletions recipes/libnetfilter_conntrack/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.0.8":
sha256: 0cd13be008923528687af6c6b860f35392d49251c04ee0648282d36b1faec1cf
url: https://www.netfilter.org/projects/libnetfilter_conntrack/files/libnetfilter_conntrack-1.0.8.tar.bz2
67 changes: 67 additions & 0 deletions recipes/libnetfilter_conntrack/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import os
from conans import ConanFile, tools, AutoToolsBuildEnvironment
from conans.errors import ConanInvalidConfiguration

class Libnetfilter_conntrackConan(ConanFile):
name = "libnetfilter_conntrack"
license = "GPL-2.0-or-later"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://netfilter.org/projects/libnetfilter_conntrack/index.html"
description = "userspace library that provides an API to the in-kernel connection tracking state table"
topics = ("libnetfilter_conntrack", "netfilter")
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
generators = "pkg_config"
_autotools = None

@property
def _source_subfolder(self):
return "source_subfolder"

def requirements(self):
self.requires("libmnl/1.0.4")
self.requires("libnfnetlink/1.0.1")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)

def configure(self):
if self.settings.os != "Linux":
raise ConanInvalidConfiguration("libnetfilter_conntrack is only supported on Linux")
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd

def _configure_autotools(self):
if self._autotools:
return self._autotools
self._autotools = AutoToolsBuildEnvironment(self)
conf_args = []
if self.options.shared:
conf_args.extend(["--enable-shared", "--disable-static"])
else:
conf_args.extend(["--disable-shared", "--enable-static"])
self._autotools.configure(configure_dir=self._source_subfolder, args=conf_args)
return self._autotools

def build(self):
autotools = self._configure_autotools()
autotools.make()

def package(self):
self.copy("COPYING", dst="licenses", src=self._source_subfolder)
autotools = self._configure_autotools()
autotools.install()

tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la")
tools.rmdir(os.path.join(self.package_folder, "share"))
tools.rmdir(os.path.join(self.package_folder, "etc"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))

def package_info(self):
self.cpp_info.libs = ["netfilter_conntrack"]
self.cpp_info.names["pkg_config"] = "libnetfilter_conntrack"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.10)
project(PackageTest)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(example example.c)
target_link_libraries(example ${CONAN_LIBS})
17 changes: 17 additions & 0 deletions recipes/libnetfilter_conntrack/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os

from conans import ConanFile, CMake, tools

class Libnetfilter_conntrackTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "example")
self.run("{} {}".format(bin_path, 0), run_environment=True)
75 changes: 75 additions & 0 deletions recipes/libnetfilter_conntrack/all/test_package/example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <arpa/inet.h>

#include <libmnl/libmnl.h>
#include <libnetfilter_conntrack/libnetfilter_conntrack.h>

static int data_cb(const struct nlmsghdr *nlh, void *data)
{
struct nf_conntrack *ct;
char buf[4096];

ct = nfct_new();
if (ct == NULL)
return MNL_CB_OK;

nfct_nlmsg_parse(nlh, ct);

nfct_snprintf(buf, sizeof(buf), ct, NFCT_T_UNKNOWN, NFCT_O_DEFAULT, 0);
printf("%s\n", buf);

nfct_destroy(ct);

return MNL_CB_OK;
}

int main(void)
{
struct mnl_socket *nl;
struct nlmsghdr *nlh;
struct nfgenmsg *nfh;
char buf[MNL_SOCKET_BUFFER_SIZE];
unsigned int seq, portid;
int ret;

nl = mnl_socket_open(NETLINK_NETFILTER);
if (nl == NULL) {
perror("mnl_socket_open");
exit(EXIT_FAILURE);
}

if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
perror("mnl_socket_bind");
exit(EXIT_FAILURE);
}
portid = mnl_socket_get_portid(nl);

nlh = mnl_nlmsg_put_header(buf);
nlh->nlmsg_type = (NFNL_SUBSYS_CTNETLINK << 8) | IPCTNL_MSG_CT_GET;
nlh->nlmsg_flags = NLM_F_REQUEST|NLM_F_DUMP;
nlh->nlmsg_seq = seq = time(NULL);

nfh = mnl_nlmsg_put_extra_header(nlh, sizeof(struct nfgenmsg));
nfh->nfgen_family = AF_INET;
nfh->version = NFNETLINK_V0;
nfh->res_id = 0;

ret = mnl_socket_sendto(nl, nlh, nlh->nlmsg_len);
if (ret == -1) {
perror("mnl_socket_recvfrom");
exit(EXIT_FAILURE);
}

ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
if (ret == -1) {
perror("mnl_socket_recvfrom");
exit(EXIT_FAILURE);
}

mnl_socket_close(nl);

return 0;
}
3 changes: 3 additions & 0 deletions recipes/libnetfilter_conntrack/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
1.0.8:
folder: all

0 comments on commit 5e2ee46

Please sign in to comment.