netfilter
firewalling, NAT, and packet mangling for linux
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
nssocket.c File Reference
#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>
Include dependency graph for nssocket.c:

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_socketmnl_nssocket_open (int bus)
 
struct nf_conntrackauthor_new (const struct nlmsghdr *nlh, void *data)
 
struct nf_conntrackauthor_update (const struct nlmsghdr *nlh, void *data)
 
struct nf_conntrackauthor_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_socketmnl_event_nssocket (const char *nsname)
 
void sync_fifo (const char *name)
 

Variables

int fdpair [2]
 
pid_t child_pid
 

Macro Definition Documentation

#define CHILD_FD   (fdpair[1])
#define NETNS_RUN_DIR   "/var/run/netns"
#define PARENT_FD   (fdpair[0])

Function Documentation

void add_child ( pid_t  pid)

References children, and nchild.

Referenced by init_nssocket().

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

void assert_port ( const struct nf_conntrack ct,
u_int16_t  src,
u_int16_t  dst 
)
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().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

struct nf_conntrack* author_new ( const struct nlmsghdr nlh,
void *  data 
)
int cb_icmp_destroy ( const struct nlmsghdr nlh,
void *  data 
)

References assert_typecode(), author_destroy(), ct, ICMP_CODE, ICMP_TYPE, MNL_CB_OK, and nfct_destroy().

Here is the call graph for this function:

int cb_icmp_new ( const struct nlmsghdr nlh,
void *  data 
)

References assert_typecode(), author_new(), ct, ICMP_CODE, ICMP_TYPE, MNL_CB_OK, and nfct_destroy().

Here is the call graph for this function:

int cb_icmp_update ( const struct nlmsghdr nlh,
void *  data 
)

References assert_typecode(), author_update(), ct, ICMP_CODE, ICMP_TYPE, MNL_CB_OK, and nfct_destroy().

Here is the call graph for this function:

int cb_tcp_close ( const struct nlmsghdr nlh,
void *  data 
)

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().

Here is the call graph for this function:

Here is the caller graph for this function:

int cb_tcp_close_wait ( const struct nlmsghdr nlh,
void *  data 
)

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().

Here is the call graph for this function:

Here is the caller graph for this function:

int cb_tcp_destroy ( const struct nlmsghdr nlh,
void *  data 
)

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().

Here is the call graph for this function:

Here is the caller graph for this function:

int cb_tcp_established ( const struct nlmsghdr nlh,
void *  data 
)

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().

Here is the call graph for this function:

Here is the caller graph for this function:

int cb_tcp_fin_wait ( const struct nlmsghdr nlh,
void *  data 
)

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().

Here is the call graph for this function:

Here is the caller graph for this function:

int cb_tcp_new ( const struct nlmsghdr nlh,
void *  data 
)

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().

Here is the call graph for this function:

Here is the caller graph for this function:

int cb_tcp_syn_recv ( const struct nlmsghdr nlh,
void *  data 
)

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().

Here is the call graph for this function:

Here is the caller graph for this function:

int cb_udp_destroy ( const struct nlmsghdr nlh,
void *  data 
)

References assert_port(), author_destroy(), ct, MNL_CB_OK, and nfct_destroy().

Here is the call graph for this function:

int cb_udp_new ( const struct nlmsghdr nlh,
void *  data 
)

References assert_port(), author_new(), ct, MNL_CB_OK, and nfct_destroy().

Here is the call graph for this function:

int cb_udp_update ( const struct nlmsghdr nlh,
void *  data 
)

References assert_port(), author_update(), ct, MNL_CB_OK, and nfct_destroy().

Here is the call graph for this function:

int debug_nfct_cb ( const struct nlmsghdr nlh,
void *  data 
)
int fini_nssocket ( void  )

References child_pid, CMD_DONE, NULL, PARENT_FD, pid_t, and tx_cmd().

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

struct mnl_socket* mnl_nssocket_open ( int  bus)

References mnl_socket::fd, mnl_socket_fdopen(), nssocket(), and NULL.

Referenced by mnl_event_nssocket().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

ssize_t rx ( int  fd,
int *  cmd,
uint8_t  cmdlen,
int *  cdata 
)

References NULL.

Referenced by mpz_and(), mpz_ior(), mpz_xor(), rx_cmd(), and rx_fd().

Here is the caller graph for this function:

int rx_cmd ( int  fd)

References NULL, and rx().

Referenced by init_nssocket().

Here is the call graph for this function:

Here is the caller graph for this function:

int rx_fd ( int  fd1)

References rx().

Referenced by nssocket().

Here is the call graph for this function:

Here is the caller graph for this function:

void sync_fifo ( const char *  name)

References parent_fail.

Referenced by tcp_echo().

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

ssize_t tx ( int  fd,
int *  cmd,
uint8_t  cmdlen,
int  cdata 
)

Referenced by nssocket(), tx_cmd(), and tx_fd().

Here is the caller graph for this function:

int tx_cmd ( int  fd,
int  cmd 
)

References tx().

Referenced by fini_nssocket().

Here is the call graph for this function:

Here is the caller graph for this function:

int tx_fd ( int  fd1,
int  fd2,
int  e 
)

References tx().

Here is the call graph for this function:

Variable Documentation

pid_t child_pid
int fdpair[2]

Referenced by init_nssocket().