Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
intltool \
libtool \
make \
pkg-config \
sed

- name: autogen
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ autom4te.cache/

src/.libs/
src/*.l*
src/*.gcda
src/*.gcno
tests/.libs/
tests/test
test/gwtest
test/*.gcda
test/*.gcno

*~
*.o
Expand Down
4 changes: 4 additions & 0 deletions GNUmakefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ SUBDIRS = \
config \
src

if ENABLE_TEST
SUBDIRS += test
endif

EXTRA_DIST = \
autogen.sh \
config/m4/.secret-world-domination-project
Expand Down
40 changes: 39 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ if test "${CONFIG_DEBUG}" = "yes"; then
CFLAGS="${CFLAGS} -Werror -Wsign-compare -Wfloat-equal -Wformat-security -g -O1"
AC_DEFINE(DEBUG, 1, [debugging])
else
CFLAGS="${CFLAGS} -O2"
CFLAGS="${CFLAGS} -g -O2"
fi


Expand All @@ -115,13 +115,51 @@ if test "${CONFIG_ERROR_LOG}" = "no"; then
AC_DEFINE(DISABLE_ERROR_LOG, 1, [disable error logging])
fi

#
# Enable gcov
#
AC_MSG_CHECKING([whether to enable gcov])
AC_ARG_ENABLE([gcov],
[AS_HELP_STRING([--enable-gcov], [Enable gcov in build time (for debug, default is no)])],
[:],
[enable_gcov=no])
AC_MSG_RESULT([$enable_gcov])
if test "$enable_gcov" = "yes"; then
CFLAGS="${CFLAGS} -coverage"
fi

#
# Enable address-sanitizer
#
AC_MSG_CHECKING([whether to enable address-sanitizer])
AC_ARG_ENABLE([address-sanitizer],
[AS_HELP_STRING([--enable-address-sanitizer], [Enable address sanitizer in build time (for debug, default is no)])],
[:],
[enable_address_sanitizer=no])
AC_MSG_RESULT([$enable_address_sanitizer])
if test "$enable_address_sanitizer" = "yes"; then
CFLAGS="${CFLAGS} -fsanitize=address"
fi

#
# Enable unit test
#
AC_ARG_ENABLE([test],
[AS_HELP_STRING([--enable-test], [Enable unit test build (cmocka is required, default is no])],
[:],
[enable_test=no])
AM_CONDITIONAL([ENABLE_TEST], [test "$enable_test" = "yes"])
AS_CASE(
["$enable_test"],
[yes], [PKG_CHECK_MODULES([CMOCKA], [cmocka])],[])

AC_CONFIG_FILES([
GNUmakefile
config/libsocketcan.pc
config/GNUmakefile
include/GNUmakefile
src/GNUmakefile
test/GNUmakefile
])
AC_OUTPUT

1 change: 1 addition & 0 deletions include/GNUmakefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
nobase_include_HEADERS = \
libsocketcan.h \
libsocketcangw.h \
can_netlink.h

MAINTAINERCLEANFILES = \
Expand Down
65 changes: 65 additions & 0 deletions include/libsocketcangw.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* libsocketcangw.h
*
* (C) 2025 Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or any later version.
*
* This library 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 lesser general public license for more
* details.
*
* you should have received a copy of the gnu lesser general public license
* along with this library; if not, write to the free software foundation, inc.,
* 59 temple place, suite 330, boston, ma 02111-1307 usa
*/

#ifndef _socketcangw_netlink_h
#define _socketcangw_netlink_h

/**
* @file
* @brief API overview
*/
#include <linux/can.h>

#ifdef __cplusplus
extern "C" {
#endif

#define SOCKETCAN_GW_RULE_ECHO (0x00000001U)
#define SOCKETCAN_GW_RULE_FILTER (0x00000002U)

struct s_socketcan_gw_rule {
unsigned int src_ifindex;
unsigned int dst_ifindex;

unsigned int options;

unsigned int echo;
struct can_filter filter;
};
typedef struct s_socketcan_gw_rule socketcan_gw_rule_t;

struct s_socketcan_gw_rules {
size_t rule_num;
socketcan_gw_rule_t **rules;
// internal use
size_t array_num;
};
typedef struct s_socketcan_gw_rules socketcan_gw_rules_t;

int cangw_add_rule(socketcan_gw_rule_t *rule);
int cangw_delete_rule(socketcan_gw_rule_t *rule);
int cangw_clean_rule(void);
int cangw_get_rules(socketcan_gw_rules_t **gw_rules);
int cangw_release_rules(socketcan_gw_rules_t *gw_rules);

#ifdef __cplusplus
}
#endif

#endif
7 changes: 6 additions & 1 deletion src/GNUmakefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/include \
-I$(top_builddir)/include

libsocketcan_la_SOURCES = libsocketcan.c
libsocketcan_la_SOURCES = \
libsocketcan-utils.c \
libsocketcan.c \
libcangw.c

libsocketcan_la_LDFLAGS = \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
Expand All @@ -15,3 +18,5 @@ libsocketcan_la_LDFLAGS = \
#
MAINTAINERCLEANFILES = \
GNUmakefile.in

CLEANFILES = *.gcda *.gcno
Loading