Skip to contentSkip to conversation

libnfnetlink: Add API support for passing bound file descriptor

PATCH In review Skylar Chang 2 participants 2 messages Apr 3, 2017 – Apr 8, 2017 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libnfnetlink: Add API support for passing bound file descriptor

Add API support to accept pre-bound file descriptor from a privileged process for creating a handle. Also clean-up the handle without close the passing file descriptor. This paves the path for privilege separation.

---
 include/libnfnetlink/libnfnetlink.h |   7 +++
 src/libnfnetlink.c                  | 116 ++++++++++++++++++++++++++++++------
 2 files changed, 106 insertions(+), 17 deletions(-)
include/libnfnetlink/libnfnetlink.h +7 -0
index cd0be3d..437eb55 100644
@@ -19,6 +19,7 @@
 #include <sys/socket.h>	/* for sa_family_t */
 #include <linux/netlink.h>
 #include <libnfnetlink/linux_nfnetlink.h>
+#include <stdbool.h>
 
 #ifndef NETLINK_NETFILTER
 #define NETLINK_NETFILTER 12
@@ -67,11 +68,17 @@ extern unsigned int nfnl_portid(const struct nfnl_handle *h);
 
 /* get a new library handle */
 extern struct nfnl_handle *nfnl_open(void);
+extern struct nfnl_handle *nfnl_open2(int fd, bool bind);
 extern int nfnl_close(struct nfnl_handle *);
+extern int nfnl_close2(struct nfnl_handle *);
 
 extern struct nfnl_subsys_handle *nfnl_subsys_open(struct nfnl_handle *, 
 						   uint8_t, uint8_t,
 						   unsigned int);
+extern struct nfnl_subsys_handle *nfnl_subsys_open2(struct nfnl_handle *,
+						   u_int8_t, u_int8_t,
+						   unsigned int,
+						   bool bind);
 extern void nfnl_subsys_close(struct nfnl_subsys_handle *);
 
 /* set and unset sequence tracking */
src/libnfnetlink.c +99 -17

192 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw
Quoted 4 lines · Skylar Chang

Add API support to accept pre-bound file descriptor from a privileged process for creating a handle. Also clean-up the handle without close the passing file descriptor. This paves the path for privilege separation.

I can take this patch... But as things are going, I would very much push for libnfnetlink deprecation, so this API may be soon deprecated which would be weird as it would be just something new...

It would be much better if you use libmnl for this. There's a new API in libnetfilter_conntrack that mixes well with it.

Let me know.