#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <libmnl/libmnl.h>
#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
#include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
#include "config.h"
#include "nssocket.h"
#include <sys/syscall.h>
Macros | |
#define | PARENT_FD (fdpair[0]) |
#define | CHILD_FD (fdpair[1]) |
#define | NETNS_RUN_DIR "/var/run/netns" |
Functions | |
void | add_child (pid_t pid) |
ssize_t | tx (int fd, int *cmd, uint8_t cmdlen, int cdata) |
ssize_t | rx (int fd, int *cmd, uint8_t cmdlen, int *cdata) |
int | tx_cmd (int fd, int cmd) |
int | rx_cmd (int fd) |
int | tx_fd (int fd1, int fd2, int e) |
int | rx_fd (int fd1) |
int | init_nssocket (const char *nsname) |
int | fini_nssocket (void) |
int | nssocket (int domain, int type, int protocol) |
int | debug_nfct_cb (const struct nlmsghdr *nlh, void *data) |
struct mnl_socket * | mnl_nssocket_open (int bus) |
struct nf_conntrack * | author_new (const struct nlmsghdr *nlh, void *data) |
struct nf_conntrack * | author_update (const struct nlmsghdr *nlh, void *data) |
struct nf_conntrack * | author_destroy (const struct nlmsghdr *nlh, void *data) |
void | assert_proto (const struct nf_conntrack *ct, u_int8_t l3proto, u_int8_t l4proto) |
void | assert_inaddr (const struct nf_conntrack *ct, const char *src, const char *dst) |
void | assert_port (const struct nf_conntrack *ct, u_int16_t src, u_int16_t dst) |
void | assert_typecode (const struct nf_conntrack *ct, u_int8_t type, u_int8_t code) |
int | cb_icmp_new (const struct nlmsghdr *nlh, void *data) |
int | cb_icmp_update (const struct nlmsghdr *nlh, void *data) |
int | cb_icmp_destroy (const struct nlmsghdr *nlh, void *data) |
int | cb_udp_new (const struct nlmsghdr *nlh, void *data) |
int | cb_udp_update (const struct nlmsghdr *nlh, void *data) |
int | cb_udp_destroy (const struct nlmsghdr *nlh, void *data) |
int | cb_tcp_new (const struct nlmsghdr *nlh, void *data) |
int | cb_tcp_syn_recv (const struct nlmsghdr *nlh, void *data) |
int | cb_tcp_established (const struct nlmsghdr *nlh, void *data) |
int | cb_tcp_fin_wait (const struct nlmsghdr *nlh, void *data) |
int | cb_tcp_close_wait (const struct nlmsghdr *nlh, void *data) |
int | cb_tcp_close (const struct nlmsghdr *nlh, void *data) |
int | cb_tcp_destroy (const struct nlmsghdr *nlh, void *data) |
void | tcp_echo (const struct mnl_socket *nl, const char *pre, const char *post) |
int | handle_qacb (const struct mnl_socket *nl, bool should_receive, int(*cb)(const struct nlmsghdr *nlh, void *data), void *data) |
struct mnl_socket * | mnl_event_nssocket (const char *nsname) |
void | sync_fifo (const char *name) |
Variables | |
int | fdpair [2] |
pid_t | child_pid |
#define CHILD_FD (fdpair[1]) |
#define NETNS_RUN_DIR "/var/run/netns" |
#define PARENT_FD (fdpair[0]) |
Referenced by fini_nssocket(), init_nssocket(), and nssocket().
void add_child | ( | pid_t | pid | ) |
References children, and nchild.
Referenced by init_nssocket().
void assert_inaddr | ( | const struct nf_conntrack * | ct, |
const char * | src, | ||
const char * | dst | ||
) |
References ATTR_ORIG_IPV4_DST, ATTR_ORIG_IPV4_SRC, ATTR_REPL_IPV4_DST, ATTR_REPL_IPV4_SRC, and nfct_get_attr_u32().
Referenced by author_destroy(), author_new(), and author_update().
void assert_port | ( | const struct nf_conntrack * | ct, |
u_int16_t | src, | ||
u_int16_t | dst | ||
) |
References ATTR_ORIG_PORT_DST, ATTR_ORIG_PORT_SRC, ATTR_REPL_PORT_DST, ATTR_REPL_PORT_SRC, and nfct_get_attr_u16().
Referenced by cb_tcp_close(), cb_tcp_close_wait(), cb_tcp_destroy(), cb_tcp_established(), cb_tcp_fin_wait(), cb_tcp_new(), cb_tcp_syn_recv(), cb_udp_destroy(), cb_udp_new(), and cb_udp_update().
void assert_proto | ( | const struct nf_conntrack * | ct, |
u_int8_t | l3proto, | ||
u_int8_t | l4proto | ||
) |
References ATTR_ORIG_L3PROTO, ATTR_ORIG_L4PROTO, ATTR_REPL_L3PROTO, ATTR_REPL_L4PROTO, and nfct_get_attr_u8().
Referenced by author_destroy(), author_new(), and author_update().
void assert_typecode | ( | const struct nf_conntrack * | ct, |
u_int8_t | type, | ||
u_int8_t | code | ||
) |
References ATTR_ICMP_CODE, ATTR_ICMP_TYPE, and nfct_get_attr_u8().
Referenced by cb_icmp_destroy(), cb_icmp_new(), and cb_icmp_update().
struct nf_conntrack* author_destroy | ( | const struct nlmsghdr * | nlh, |
void * | data | ||
) |
References assert_inaddr(), assert_proto(), ATTR_STATUS, ct, IPCTNL_MSG_CT_DELETE, IPS_SEEN_REPLY, nfct_get_attr_u32(), nfct_new(), nfct_nlmsg_parse(), nlmsghdr::nlmsg_flags, nlmsghdr::nlmsg_type, and NULL.
Referenced by cb_icmp_destroy(), cb_tcp_destroy(), and cb_udp_destroy().
struct nf_conntrack* author_new | ( | const struct nlmsghdr * | nlh, |
void * | data | ||
) |
References assert_inaddr(), assert_proto(), ATTR_STATUS, ATTR_TIMEOUT, ct, IPCTNL_MSG_CT_NEW, IPS_SEEN_REPLY, nfct_get_attr_u32(), nfct_new(), nfct_nlmsg_parse(), NLM_F_CREATE, NLM_F_EXCL, nlmsghdr::nlmsg_flags, nlmsghdr::nlmsg_type, NULL, and timeout.
Referenced by cb_icmp_new(), cb_tcp_new(), and cb_udp_new().
struct nf_conntrack* author_update | ( | const struct nlmsghdr * | nlh, |
void * | data | ||
) |
References assert_inaddr(), assert_proto(), ATTR_STATUS, ATTR_TIMEOUT, ct, IPCTNL_MSG_CT_NEW, IPS_SEEN_REPLY, nfct_get_attr_u32(), nfct_new(), nfct_nlmsg_parse(), nlmsghdr::nlmsg_flags, nlmsghdr::nlmsg_type, NULL, and timeout.
Referenced by cb_icmp_update(), cb_tcp_close(), cb_tcp_close_wait(), cb_tcp_established(), cb_tcp_fin_wait(), cb_tcp_syn_recv(), and cb_udp_update().
References assert_typecode(), author_destroy(), ct, ICMP_CODE, ICMP_TYPE, MNL_CB_OK, and nfct_destroy().
References assert_typecode(), author_new(), ct, ICMP_CODE, ICMP_TYPE, MNL_CB_OK, and nfct_destroy().
References assert_typecode(), author_update(), ct, ICMP_CODE, ICMP_TYPE, MNL_CB_OK, and nfct_destroy().
References assert_port(), ATTR_STATUS, ATTR_TCP_STATE, author_update(), ct, IPS_ASSURED, MNL_CB_OK, nfct_destroy(), nfct_get_attr_u32(), nfct_get_attr_u8(), and TCP_CONNTRACK_CLOSE.
Referenced by tcp_echo().
References assert_port(), ATTR_STATUS, ATTR_TCP_STATE, author_update(), ct, IPS_ASSURED, MNL_CB_OK, nfct_destroy(), nfct_get_attr_u32(), nfct_get_attr_u8(), and TCP_CONNTRACK_CLOSE_WAIT.
Referenced by tcp_echo().
References assert_port(), ATTR_STATUS, ATTR_TCP_STATE, author_destroy(), ct, IPS_ASSURED, MNL_CB_OK, nfct_attr_is_set(), nfct_destroy(), and nfct_get_attr_u32().
Referenced by tcp_echo().
References assert_port(), ATTR_STATUS, ATTR_TCP_STATE, author_update(), ct, IPS_ASSURED, MNL_CB_OK, nfct_destroy(), nfct_get_attr_u32(), nfct_get_attr_u8(), and TCP_CONNTRACK_ESTABLISHED.
Referenced by tcp_echo().
References assert_port(), ATTR_STATUS, ATTR_TCP_STATE, author_update(), ct, IPS_ASSURED, MNL_CB_OK, nfct_destroy(), nfct_get_attr_u32(), nfct_get_attr_u8(), and TCP_CONNTRACK_FIN_WAIT.
Referenced by tcp_echo().
References assert_port(), ATTR_TCP_STATE, author_new(), ct, MNL_CB_OK, nfct_destroy(), nfct_get_attr_u8(), and TCP_CONNTRACK_SYN_SENT.
Referenced by tcp_echo().
References assert_port(), ATTR_TCP_STATE, author_update(), ct, MNL_CB_OK, nfct_destroy(), nfct_get_attr_u8(), and TCP_CONNTRACK_SYN_RECV.
Referenced by tcp_echo().
References assert_port(), author_destroy(), ct, MNL_CB_OK, and nfct_destroy().
References assert_port(), author_new(), ct, MNL_CB_OK, and nfct_destroy().
References assert_port(), author_update(), ct, MNL_CB_OK, and nfct_destroy().
References buf, ct, debug, IPCTNL_MSG_CT_DELETE, IPCTNL_MSG_CT_NEW, MNL_CB_OK, nfct_destroy(), nfct_new(), nfct_nlmsg_parse(), NFCT_O_DEFAULT, nfct_snprintf(), NFCT_T_DESTROY, NFCT_T_NEW, NFCT_T_UNKNOWN, NFCT_T_UPDATE, NLM_F_CREATE, NLM_F_EXCL, nlmsghdr::nlmsg_flags, nlmsghdr::nlmsg_type, and NULL.
Referenced by handle_qacb().
int fini_nssocket | ( | void | ) |
int handle_qacb | ( | const struct mnl_socket * | nl, |
bool | should_receive, | ||
int(*)(const struct nlmsghdr *nlh, void *data) | cb, | ||
void * | data | ||
) |
References buf, child_exit, debug_nfct_cb(), MNL_CB_ERROR, MNL_CB_OK, mnl_cb_run(), MNL_SOCKET_BUFFER_SIZE, mnl_socket_get_fd(), mnl_socket_recvfrom(), NULL, and timeout.
Referenced by tcp_echo().
int init_nssocket | ( | const char * | nsname | ) |
References add_child(), child_pid, fdpair, NULL, parent_fail, PARENT_FD, pid_t, and rx_cmd().
Referenced by mnl_event_nssocket().
struct mnl_socket* mnl_event_nssocket | ( | const char * | nsname | ) |
References init_nssocket(), mnl_nssocket_open(), MNL_SOCKET_AUTOPID, mnl_socket_bind(), mnl_socket_close(), NETLINK_NETFILTER, NF_NETLINK_CONNTRACK_DESTROY, NF_NETLINK_CONNTRACK_NEW, NF_NETLINK_CONNTRACK_UPDATE, NULL, and parent_fail.
Referenced by main().
struct mnl_socket* mnl_nssocket_open | ( | int | bus | ) |
References mnl_socket::fd, mnl_socket_fdopen(), nssocket(), and NULL.
Referenced by mnl_event_nssocket().
int nssocket | ( | int | domain, |
int | type, | ||
int | protocol | ||
) |
References child_pid, CMD_SOCKET, PARENT_FD, rx_fd(), tx(), and type.
Referenced by mnl_nssocket_open().
ssize_t rx | ( | int | fd, |
int * | cmd, | ||
uint8_t | cmdlen, | ||
int * | cdata | ||
) |
int rx_cmd | ( | int | fd | ) |
Referenced by init_nssocket().
int rx_fd | ( | int | fd1 | ) |
References rx().
Referenced by nssocket().
void sync_fifo | ( | const char * | name | ) |
void tcp_echo | ( | const struct mnl_socket * | nl, |
const char * | pre, | ||
const char * | post | ||
) |
References cb_tcp_close(), cb_tcp_close_wait(), cb_tcp_destroy(), cb_tcp_established(), cb_tcp_fin_wait(), cb_tcp_new(), cb_tcp_syn_recv(), handle_qacb(), NULL, sync_fifo(), and timeout.
Referenced by main().
ssize_t tx | ( | int | fd, |
int * | cmd, | ||
uint8_t | cmdlen, | ||
int | cdata | ||
) |
int tx_cmd | ( | int | fd, |
int | cmd | ||
) |
References tx().
Referenced by fini_nssocket().
int tx_fd | ( | int | fd1, |
int | fd2, | ||
int | e | ||
) |
pid_t child_pid |
Referenced by fini_nssocket(), init_nssocket(), and nssocket().
int fdpair[2] |
Referenced by init_nssocket().