Modules | |
Conntrack | |
Log | |
Socket Creating | |
| |
int | nfnl_connect (struct nl_handle *handle) |
Create and connect netfilter netlink socket. | |
Sending | |
| |
int | nfnl_send_simple (struct nl_handle *handle, uint8_t subsys_id, uint8_t type, int flags, uint8_t family, uint16_t res_id) |
Send trivial netfilter netlink message. | |
Message Parsing | |
| |
uint8_t | nfnlmsg_subsys (struct nlmsghdr *nlh) |
Get netfilter subsystem id from message. | |
uint8_t | nfnlmsg_subtype (struct nlmsghdr *nlh) |
Get netfilter message type from message. | |
uint8_t | nfnlmsg_family (struct nlmsghdr *nlh) |
Get netfilter family from message. | |
uint16_t | nfnlmsg_res_id (struct nlmsghdr *nlh) |
Get netfilter resource id from message. | |
Message Building | |
| |
struct nl_msg * | nfnlmsg_alloc_simple (uint8_t subsys_id, uint8_t type, int flags, uint8_t family, uint16_t res_id) |
Allocate a new netfilter netlink message. | |
int | nfnlmsg_put (struct nl_msg *msg, uint32_t pid, uint32_t seq, uint8_t subsys_id, uint8_t type, int flags, uint8_t family, uint16_t res_id) |
Add netlink and netfilter netlink headers to netlink message. |
<------- NLMSG_ALIGN(hlen) ------> <---- NLMSG_ALIGN(len) ---> +----------------------------+- - -+- - - - - - - - - - -+- - -+ | Header | Pad | Payload | Pad | | struct nlmsghdr | | | | +----------------------------+- - -+- - - - - - - - - - -+- - -+
<-------- NFNL_HDRLEN --------->
+--------------------------+- - -+------------+
| Netfilter Netlink Header | Pad | Attributes |
| struct nfgenmsg | | |
+--------------------------+- - -+------------+
nfnlmsg_attrdata(nfg, hdrlen)-----^
struct nl_msg *msg; // Create a new empty netlink message msg = nlmsg_alloc(); // Append the netlink and netfilter netlink message header hdr = nfnlmsg_put(msg, PID, SEQ, SUBSYS, TYPE, NLM_F_ECHO, FAMILY, RES_ID); // Append the attributes. nla_put_u32(msg, 1, 0x10); // Message is ready to be sent. nl_send_auto_complete(nl_handle, msg); // All done? Free the message. nlmsg_free(msg);
// For trivial messages not requiring any subsys specific header or // attributes, nfnl_send_simple() may be used to send messages directly. nfnl_send_simple(nl_handle, SUBSYS, TYPE, 0, FAMILY, RES_ID);
int nfnl_connect | ( | struct nl_handle * | handle | ) |
handle | Netlink handle. |
Creates a NETLINK_NETFILTER netlink socket, binds the socket and issues a connection attempt.
Definition at line 85 of file nfnl.c.
References nl_connect().
00086 { 00087 return nl_connect(handle, NETLINK_NETFILTER); 00088 }
int nfnl_send_simple | ( | struct nl_handle * | handle, | |
uint8_t | subsys_id, | |||
uint8_t | type, | |||
int | flags, | |||
uint8_t | family, | |||
uint16_t | res_id | |||
) |
handle | Netlink handle. | |
subsys_id | nfnetlink subsystem | |
type | nfnetlink message type | |
flags | message flags | |
family | nfnetlink address family | |
res_id | nfnetlink resource id |
Definition at line 108 of file nfnl.c.
References nl_send_simple().
00110 { 00111 struct nfgenmsg hdr = { 00112 .nfgen_family = family, 00113 .version = NFNETLINK_V0, 00114 .res_id = htons(res_id), 00115 }; 00116 00117 return nl_send_simple(handle, NFNLMSG_TYPE(subsys_id, type), flags, 00118 &hdr, sizeof(hdr)); 00119 }
uint8_t nfnlmsg_subsys | ( | struct nlmsghdr * | nlh | ) |
nlh | netlink messsage header |
Definition at line 132 of file nfnl.c.
References nlmsghdr::nlmsg_type.
00133 { 00134 return NFNL_SUBSYS_ID(nlh->nlmsg_type); 00135 }
uint8_t nfnlmsg_subtype | ( | struct nlmsghdr * | nlh | ) |
nlh | netlink messsage header |
Definition at line 141 of file nfnl.c.
References nlmsghdr::nlmsg_type.
00142 { 00143 return NFNL_MSG_TYPE(nlh->nlmsg_type); 00144 }
uint8_t nfnlmsg_family | ( | struct nlmsghdr * | nlh | ) |
nlh | netlink messsage header |
Definition at line 150 of file nfnl.c.
References nlmsg_data().
00151 { 00152 struct nfgenmsg *nfg = nlmsg_data(nlh); 00153 00154 return nfg->nfgen_family; 00155 }
uint16_t nfnlmsg_res_id | ( | struct nlmsghdr * | nlh | ) |
nlh | netlink messsage header |
Definition at line 161 of file nfnl.c.
References nlmsg_data().
00162 { 00163 struct nfgenmsg *nfg = nlmsg_data(nlh); 00164 00165 return ntohs(nfg->res_id); 00166 }
struct nl_msg* nfnlmsg_alloc_simple | ( | uint8_t | subsys_id, | |
uint8_t | type, | |||
int | flags, | |||
uint8_t | family, | |||
uint16_t | res_id | |||
) | [read] |
subsys_id | nfnetlink subsystem | |
type | nfnetlink message type | |
flags | message flags | |
family | nfnetlink address family | |
res_id | nfnetlink resource id |
Definition at line 201 of file nfnl.c.
References nlmsg_alloc_simple(), and nlmsg_free().
00203 { 00204 struct nl_msg *msg; 00205 00206 msg = nlmsg_alloc_simple(NFNLMSG_TYPE(subsys_id, type), flags); 00207 if (msg == NULL) 00208 return NULL; 00209 00210 if (nfnlmsg_append(msg, family, res_id) < 0) 00211 goto nla_put_failure; 00212 00213 return msg; 00214 00215 nla_put_failure: 00216 nlmsg_free(msg); 00217 return NULL; 00218 }
int nfnlmsg_put | ( | struct nl_msg * | msg, | |
uint32_t | pid, | |||
uint32_t | seq, | |||
uint8_t | subsys_id, | |||
uint8_t | type, | |||
int | flags, | |||
uint8_t | family, | |||
uint16_t | res_id | |||
) |
msg | netlink message | |
pid | netlink process id | |
seq | sequence number of message | |
subsys_id | nfnetlink subsystem | |
type | nfnetlink message type | |
flags | message flags | |
family | nfnetlink address family | |
res_id | nfnetlink resource id |
Definition at line 231 of file nfnl.c.
References nlmsg_put().