* [PATCH libmnl 0/2] Introduce mnl_socket_open2()
@ 2015-10-02 20:12 Guillaume Nault
2015-10-02 20:12 ` [PATCH libmnl 1/2] socket: introduce mnl_socket_open2() Guillaume Nault
2015-10-02 20:12 ` [PATCH libmnl 2/2] examples: use mnl_socket_open2() Guillaume Nault
0 siblings, 2 replies; 11+ messages in thread
From: Guillaume Nault @ 2015-10-02 20:12 UTC (permalink / raw)
To: netfilter-devel
mnl_socket_open2() extends mnl_socket_open() with user provided flags, to
be used in the socket() call.
Patch #1 implements the new function while patch #2 updates the
examples by applying the SOCK_CLOEXEC flag on netlink sockets. Though
it's a safe default, this flag isn't necessary for the simple programs
under examples/. So feel free to drop patch #2 if considered of too
little value.
Guillaume Nault (2):
socket: introduce mnl_socket_open2()
examples: use mnl_socket_open2()
examples/genl/genl-family-get.c | 4 ++--
examples/genl/genl-group-events.c | 4 ++--
examples/kobject/kobject-event.c | 4 ++--
examples/netfilter/nf-log.c | 4 ++--
examples/netfilter/nf-queue.c | 4 ++--
examples/netfilter/nfct-create-batch.c | 4 ++--
examples/netfilter/nfct-daemon.c | 4 ++--
examples/netfilter/nfct-dump.c | 4 ++--
examples/netfilter/nfct-event.c | 4 ++--
examples/rtnl/rtnl-addr-dump.c | 4 ++--
examples/rtnl/rtnl-link-dump.c | 4 ++--
examples/rtnl/rtnl-link-dump2.c | 4 ++--
examples/rtnl/rtnl-link-dump3.c | 4 ++--
examples/rtnl/rtnl-link-event.c | 4 ++--
examples/rtnl/rtnl-link-set.c | 4 ++--
examples/rtnl/rtnl-route-add.c | 4 ++--
examples/rtnl/rtnl-route-dump.c | 4 ++--
examples/rtnl/rtnl-route-event.c | 4 ++--
include/libmnl/libmnl.h | 3 ++-
src/libmnl.map | 1 +
src/socket.c | 41 ++++++++++++++++++++++++++--------
21 files changed, 71 insertions(+), 46 deletions(-)
--
2.6.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH libmnl 1/2] socket: introduce mnl_socket_open2()
2015-10-02 20:12 [PATCH libmnl 0/2] Introduce mnl_socket_open2() Guillaume Nault
@ 2015-10-02 20:12 ` Guillaume Nault
2015-10-05 15:37 ` Pablo Neira Ayuso
` (2 more replies)
2015-10-02 20:12 ` [PATCH libmnl 2/2] examples: use mnl_socket_open2() Guillaume Nault
1 sibling, 3 replies; 11+ messages in thread
From: Guillaume Nault @ 2015-10-02 20:12 UTC (permalink / raw)
To: netfilter-devel
Define mnl_socket_open2() so that user can pass a set of SOCK_* flags
at socket creation time.
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
---
include/libmnl/libmnl.h | 3 ++-
src/libmnl.map | 1 +
src/socket.c | 41 ++++++++++++++++++++++++++++++++---------
3 files changed, 35 insertions(+), 10 deletions(-)
diff --git a/include/libmnl/libmnl.h b/include/libmnl/libmnl.h
index 3a589bc..5adb13c 100644
--- a/include/libmnl/libmnl.h
+++ b/include/libmnl/libmnl.h
@@ -21,7 +21,8 @@ extern "C" {
struct mnl_socket;
-extern struct mnl_socket *mnl_socket_open(int type);
+extern struct mnl_socket *mnl_socket_open(int bus);
+extern struct mnl_socket *mnl_socket_open2(int bus, int flags);
extern struct mnl_socket *mnl_socket_fdopen(int fd);
extern int mnl_socket_bind(struct mnl_socket *nl, unsigned int groups, pid_t pid);
extern int mnl_socket_close(struct mnl_socket *nl);
diff --git a/src/libmnl.map b/src/libmnl.map
index 3c147a7..e5920e5 100644
--- a/src/libmnl.map
+++ b/src/libmnl.map
@@ -74,5 +74,6 @@ LIBMNL_1.1 {
} LIBMNL_1.0;
LIBMNL_1.2 {
+ mnl_socket_open2;
mnl_socket_fdopen;
} LIBMNL_1.1;
diff --git a/src/socket.c b/src/socket.c
index 86657d4..d63ab87 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -103,14 +103,7 @@ unsigned int mnl_socket_get_portid(const struct mnl_socket *nl)
}
EXPORT_SYMBOL(mnl_socket_get_portid);
-/**
- * mnl_socket_open - open a netlink socket
- * \param bus the netlink socket bus ID (see NETLINK_* constants)
- *
- * On error, it returns NULL and errno is appropriately set. Otherwise, it
- * returns a valid pointer to the mnl_socket structure.
- */
-struct mnl_socket *mnl_socket_open(int bus)
+static struct mnl_socket *__mnl_socket_open(int bus, int flags)
{
struct mnl_socket *nl;
@@ -118,7 +111,7 @@ struct mnl_socket *mnl_socket_open(int bus)
if (nl == NULL)
return NULL;
- nl->fd = socket(AF_NETLINK, SOCK_RAW, bus);
+ nl->fd = socket(AF_NETLINK, SOCK_RAW | flags, bus);
if (nl->fd == -1) {
free(nl);
return NULL;
@@ -126,9 +119,39 @@ struct mnl_socket *mnl_socket_open(int bus)
return nl;
}
+
+/**
+ * mnl_socket_open - open a netlink socket
+ * \param bus the netlink socket bus ID (see NETLINK_* constants)
+ *
+ * On error, it returns NULL and errno is appropriately set. Otherwise, it
+ * returns a valid pointer to the mnl_socket structure.
+ */
+struct mnl_socket *mnl_socket_open(int bus)
+{
+ return __mnl_socket_open(bus, 0);
+}
EXPORT_SYMBOL(mnl_socket_open);
/**
+ * mnl_socket_open2 - open a netlink socket with appropriate flags
+ * \param bus the netlink socket bus ID (see NETLINK_* constants)
+ * \param flags the netlink socket flags (see SOCK_* constants in socket(2))
+ *
+ * This is similar to mnl_socket_open(), but allows to set flags like
+ * SOCK_CLOEXEC at socket creation time (useful for multi-threaded programs
+ * performing exec calls).
+ *
+ * On error, it returns NULL and errno is appropriately set. Otherwise, it
+ * returns a valid pointer to the mnl_socket structure.
+ */
+struct mnl_socket *mnl_socket_open2(int bus, int flags)
+{
+ return __mnl_socket_open(bus, flags);
+}
+EXPORT_SYMBOL(mnl_socket_open2);
+
+/**
* mnl_socket_fdopen - associates a mnl_socket object with pre-existing socket.
* \param fd pre-existing socket descriptor.
*
--
2.6.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH libmnl 2/2] examples: use mnl_socket_open2()
2015-10-02 20:12 [PATCH libmnl 0/2] Introduce mnl_socket_open2() Guillaume Nault
2015-10-02 20:12 ` [PATCH libmnl 1/2] socket: introduce mnl_socket_open2() Guillaume Nault
@ 2015-10-02 20:12 ` Guillaume Nault
1 sibling, 0 replies; 11+ messages in thread
From: Guillaume Nault @ 2015-10-02 20:12 UTC (permalink / raw)
To: netfilter-devel
Open netlink sockets with the SOCK_CLOEXEC flag to provide sample usage
of the new mnl_socket_open2() function.
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
---
examples/genl/genl-family-get.c | 4 ++--
examples/genl/genl-group-events.c | 4 ++--
examples/kobject/kobject-event.c | 4 ++--
examples/netfilter/nf-log.c | 4 ++--
examples/netfilter/nf-queue.c | 4 ++--
examples/netfilter/nfct-create-batch.c | 4 ++--
examples/netfilter/nfct-daemon.c | 4 ++--
examples/netfilter/nfct-dump.c | 4 ++--
examples/netfilter/nfct-event.c | 4 ++--
examples/rtnl/rtnl-addr-dump.c | 4 ++--
examples/rtnl/rtnl-link-dump.c | 4 ++--
examples/rtnl/rtnl-link-dump2.c | 4 ++--
examples/rtnl/rtnl-link-dump3.c | 4 ++--
examples/rtnl/rtnl-link-event.c | 4 ++--
examples/rtnl/rtnl-link-set.c | 4 ++--
examples/rtnl/rtnl-route-add.c | 4 ++--
examples/rtnl/rtnl-route-dump.c | 4 ++--
examples/rtnl/rtnl-route-event.c | 4 ++--
18 files changed, 36 insertions(+), 36 deletions(-)
diff --git a/examples/genl/genl-family-get.c b/examples/genl/genl-family-get.c
index ba8de12..d2ce56f 100644
--- a/examples/genl/genl-family-get.c
+++ b/examples/genl/genl-family-get.c
@@ -206,9 +206,9 @@ int main(int argc, char *argv[])
else
nlh->nlmsg_flags |= NLM_F_DUMP;
- nl = mnl_socket_open(NETLINK_GENERIC);
+ nl = mnl_socket_open2(NETLINK_GENERIC, SOCK_CLOEXEC);
if (nl == NULL) {
- perror("mnl_socket_open");
+ perror("mnl_socket_open2");
exit(EXIT_FAILURE);
}
diff --git a/examples/genl/genl-group-events.c b/examples/genl/genl-group-events.c
index d5f0a18..8a03176 100644
--- a/examples/genl/genl-group-events.c
+++ b/examples/genl/genl-group-events.c
@@ -28,9 +28,9 @@ int main(int argc, char *argv[])
}
group = atoi(argv[1]);
- nl = mnl_socket_open(NETLINK_GENERIC);
+ nl = mnl_socket_open2(NETLINK_GENERIC, SOCK_CLOEXEC);
if (nl == NULL) {
- perror("mnl_socket_open");
+ perror("mnl_socket_open2");
exit(EXIT_FAILURE);
}
diff --git a/examples/kobject/kobject-event.c b/examples/kobject/kobject-event.c
index 97debdf..36d9647 100644
--- a/examples/kobject/kobject-event.c
+++ b/examples/kobject/kobject-event.c
@@ -13,9 +13,9 @@ int main(int argc, char *argv[])
char buf[MNL_SOCKET_BUFFER_SIZE];
int ret;
- nl = mnl_socket_open(NETLINK_KOBJECT_UEVENT);
+ nl = mnl_socket_open2(NETLINK_KOBJECT_UEVENT, SOCK_CLOEXEC);
if (nl == NULL) {
- perror("mnl_socket_open");
+ perror("mnl_socket_open2");
exit(EXIT_FAILURE);
}
diff --git a/examples/netfilter/nf-log.c b/examples/netfilter/nf-log.c
index 4383b66..ebe4f15 100644
--- a/examples/netfilter/nf-log.c
+++ b/examples/netfilter/nf-log.c
@@ -154,9 +154,9 @@ int main(int argc, char *argv[])
}
qnum = atoi(argv[1]);
- nl = mnl_socket_open(NETLINK_NETFILTER);
+ nl = mnl_socket_open2(NETLINK_NETFILTER, SOCK_CLOEXEC);
if (nl == NULL) {
- perror("mnl_socket_open");
+ perror("mnl_socket_open2");
exit(EXIT_FAILURE);
}
diff --git a/examples/netfilter/nf-queue.c b/examples/netfilter/nf-queue.c
index 957e365..78ed3e3 100644
--- a/examples/netfilter/nf-queue.c
+++ b/examples/netfilter/nf-queue.c
@@ -169,9 +169,9 @@ int main(int argc, char *argv[])
}
queue_num = atoi(argv[1]);
- nl = mnl_socket_open(NETLINK_NETFILTER);
+ nl = mnl_socket_open2(NETLINK_NETFILTER, SOCK_CLOEXEC);
if (nl == NULL) {
- perror("mnl_socket_open");
+ perror("mnl_socket_open2");
exit(EXIT_FAILURE);
}
diff --git a/examples/netfilter/nfct-create-batch.c b/examples/netfilter/nfct-create-batch.c
index 4675789..3278608 100644
--- a/examples/netfilter/nfct-create-batch.c
+++ b/examples/netfilter/nfct-create-batch.c
@@ -139,9 +139,9 @@ int main(void)
unsigned int seq, portid;
uint16_t i;
- nl = mnl_socket_open(NETLINK_NETFILTER);
+ nl = mnl_socket_open2(NETLINK_NETFILTER, SOCK_CLOEXEC);
if (nl == NULL) {
- perror("mnl_socket_open");
+ perror("mnl_socket_open2");
exit(EXIT_FAILURE);
}
if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
diff --git a/examples/netfilter/nfct-daemon.c b/examples/netfilter/nfct-daemon.c
index a97c2ec..a997717 100644
--- a/examples/netfilter/nfct-daemon.c
+++ b/examples/netfilter/nfct-daemon.c
@@ -264,9 +264,9 @@ int main(int argc, char *argv[])
nice(-20);
/* Open netlink socket to operate with netfilter */
- nl = mnl_socket_open(NETLINK_NETFILTER);
+ nl = mnl_socket_open2(NETLINK_NETFILTER, SOCK_CLOEXEC);
if (nl == NULL) {
- perror("mnl_socket_open");
+ perror("mnl_socket_open2");
exit(EXIT_FAILURE);
}
diff --git a/examples/netfilter/nfct-dump.c b/examples/netfilter/nfct-dump.c
index 114af61..7262f04 100644
--- a/examples/netfilter/nfct-dump.c
+++ b/examples/netfilter/nfct-dump.c
@@ -270,9 +270,9 @@ int main(void)
uint32_t seq, portid;
int ret;
- nl = mnl_socket_open(NETLINK_NETFILTER);
+ nl = mnl_socket_open2(NETLINK_NETFILTER, SOCK_CLOEXEC);
if (nl == NULL) {
- perror("mnl_socket_open");
+ perror("mnl_socket_open2");
exit(EXIT_FAILURE);
}
diff --git a/examples/netfilter/nfct-event.c b/examples/netfilter/nfct-event.c
index 94603d4..0c872fa 100644
--- a/examples/netfilter/nfct-event.c
+++ b/examples/netfilter/nfct-event.c
@@ -206,9 +206,9 @@ int main(void)
char buf[MNL_SOCKET_BUFFER_SIZE];
int ret;
- nl = mnl_socket_open(NETLINK_NETFILTER);
+ nl = mnl_socket_open2(NETLINK_NETFILTER, SOCK_CLOEXEC);
if (nl == NULL) {
- perror("mnl_socket_open");
+ perror("mnl_socket_open2");
exit(EXIT_FAILURE);
}
diff --git a/examples/rtnl/rtnl-addr-dump.c b/examples/rtnl/rtnl-addr-dump.c
index 6b4e52e..0d57df7 100644
--- a/examples/rtnl/rtnl-addr-dump.c
+++ b/examples/rtnl/rtnl-addr-dump.c
@@ -98,9 +98,9 @@ int main(int argc, char *argv[])
else if (strcmp(argv[1], "inet6") == 0)
rt->rtgen_family = AF_INET6;
- nl = mnl_socket_open(NETLINK_ROUTE);
+ nl = mnl_socket_open2(NETLINK_ROUTE, SOCK_CLOEXEC);
if (nl == NULL) {
- perror("mnl_socket_open");
+ perror("mnl_socket_open2");
exit(EXIT_FAILURE);
}
diff --git a/examples/rtnl/rtnl-link-dump.c b/examples/rtnl/rtnl-link-dump.c
index f5d6312..f8013b2 100644
--- a/examples/rtnl/rtnl-link-dump.c
+++ b/examples/rtnl/rtnl-link-dump.c
@@ -95,9 +95,9 @@ int main(void)
rt = mnl_nlmsg_put_extra_header(nlh, sizeof(struct rtgenmsg));
rt->rtgen_family = AF_PACKET;
- nl = mnl_socket_open(NETLINK_ROUTE);
+ nl = mnl_socket_open2(NETLINK_ROUTE, SOCK_CLOEXEC);
if (nl == NULL) {
- perror("mnl_socket_open");
+ perror("mnl_socket_open2");
exit(EXIT_FAILURE);
}
diff --git a/examples/rtnl/rtnl-link-dump2.c b/examples/rtnl/rtnl-link-dump2.c
index b3ca3fa..88e4a2c 100644
--- a/examples/rtnl/rtnl-link-dump2.c
+++ b/examples/rtnl/rtnl-link-dump2.c
@@ -68,9 +68,9 @@ int main(void)
rt = mnl_nlmsg_put_extra_header(nlh, sizeof(struct rtgenmsg));
rt->rtgen_family = AF_PACKET;
- nl = mnl_socket_open(NETLINK_ROUTE);
+ nl = mnl_socket_open2(NETLINK_ROUTE, SOCK_CLOEXEC);
if (nl == NULL) {
- perror("mnl_socket_open");
+ perror("mnl_socket_open2");
exit(EXIT_FAILURE);
}
diff --git a/examples/rtnl/rtnl-link-dump3.c b/examples/rtnl/rtnl-link-dump3.c
index 2521214..191b305 100644
--- a/examples/rtnl/rtnl-link-dump3.c
+++ b/examples/rtnl/rtnl-link-dump3.c
@@ -68,9 +68,9 @@ int main(void)
rt = mnl_nlmsg_put_extra_header(nlh, sizeof(struct rtgenmsg));
rt->rtgen_family = AF_PACKET;
- nl = mnl_socket_open(NETLINK_ROUTE);
+ nl = mnl_socket_open2(NETLINK_ROUTE, SOCK_CLOEXEC);
if (nl == NULL) {
- perror("mnl_socket_open");
+ perror("mnl_socket_open2");
exit(EXIT_FAILURE);
}
diff --git a/examples/rtnl/rtnl-link-event.c b/examples/rtnl/rtnl-link-event.c
index 123fb88..4b9f80e 100644
--- a/examples/rtnl/rtnl-link-event.c
+++ b/examples/rtnl/rtnl-link-event.c
@@ -66,9 +66,9 @@ int main(void)
char buf[MNL_SOCKET_BUFFER_SIZE];
int ret;
- nl = mnl_socket_open(NETLINK_ROUTE);
+ nl = mnl_socket_open2(NETLINK_ROUTE, SOCK_CLOEXEC);
if (nl == NULL) {
- perror("mnl_socket_open");
+ perror("mnl_socket_open2");
exit(EXIT_FAILURE);
}
diff --git a/examples/rtnl/rtnl-link-set.c b/examples/rtnl/rtnl-link-set.c
index 6086c37..43857ee 100644
--- a/examples/rtnl/rtnl-link-set.c
+++ b/examples/rtnl/rtnl-link-set.c
@@ -46,9 +46,9 @@ int main(int argc, char *argv[])
mnl_attr_put_str(nlh, IFLA_IFNAME, argv[1]);
- nl = mnl_socket_open(NETLINK_ROUTE);
+ nl = mnl_socket_open2(NETLINK_ROUTE, SOCK_CLOEXEC);
if (nl == NULL) {
- perror("mnl_socket_open");
+ perror("mnl_socket_open2");
exit(EXIT_FAILURE);
}
diff --git a/examples/rtnl/rtnl-route-add.c b/examples/rtnl/rtnl-route-add.c
index 97578cd..3465235 100644
--- a/examples/rtnl/rtnl-route-add.c
+++ b/examples/rtnl/rtnl-route-add.c
@@ -92,9 +92,9 @@ int main(int argc, char *argv[])
}
}
- nl = mnl_socket_open(NETLINK_ROUTE);
+ nl = mnl_socket_open2(NETLINK_ROUTE, SOCK_CLOEXEC);
if (nl == NULL) {
- perror("mnl_socket_open");
+ perror("mnl_socket_open2");
exit(EXIT_FAILURE);
}
diff --git a/examples/rtnl/rtnl-route-dump.c b/examples/rtnl/rtnl-route-dump.c
index 17da80b..147a801 100644
--- a/examples/rtnl/rtnl-route-dump.c
+++ b/examples/rtnl/rtnl-route-dump.c
@@ -321,9 +321,9 @@ int main(int argc, char *argv[])
else if (strcmp(argv[1], "inet6") == 0)
rtm->rtm_family = AF_INET6;
- nl = mnl_socket_open(NETLINK_ROUTE);
+ nl = mnl_socket_open2(NETLINK_ROUTE, SOCK_CLOEXEC);
if (nl == NULL) {
- perror("mnl_socket_open");
+ perror("mnl_socket_open2");
exit(EXIT_FAILURE);
}
diff --git a/examples/rtnl/rtnl-route-event.c b/examples/rtnl/rtnl-route-event.c
index 6cad9f0..9c79b0c 100644
--- a/examples/rtnl/rtnl-route-event.c
+++ b/examples/rtnl/rtnl-route-event.c
@@ -311,9 +311,9 @@ int main(int argc, char *argv[])
char buf[MNL_SOCKET_BUFFER_SIZE];
int ret;
- nl = mnl_socket_open(NETLINK_ROUTE);
+ nl = mnl_socket_open2(NETLINK_ROUTE, SOCK_CLOEXEC);
if (nl == NULL) {
- perror("mnl_socket_open");
+ perror("mnl_socket_open2");
exit(EXIT_FAILURE);
}
--
2.6.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH libmnl 1/2] socket: introduce mnl_socket_open2()
2015-10-02 20:12 ` [PATCH libmnl 1/2] socket: introduce mnl_socket_open2() Guillaume Nault
@ 2015-10-05 15:37 ` Pablo Neira Ayuso
2015-10-05 16:33 ` Guillaume Nault
2015-10-05 17:27 ` Jozsef Kadlecsik
2015-10-12 14:48 ` Pablo Neira Ayuso
2 siblings, 1 reply; 11+ messages in thread
From: Pablo Neira Ayuso @ 2015-10-05 15:37 UTC (permalink / raw)
To: Guillaume Nault; +Cc: netfilter-devel
On Fri, Oct 02, 2015 at 10:12:33PM +0200, Guillaume Nault wrote:
> Define mnl_socket_open2() so that user can pass a set of SOCK_* flags
> at socket creation time.
>
> Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
> ---
> include/libmnl/libmnl.h | 3 ++-
> src/libmnl.map | 1 +
> src/socket.c | 41 ++++++++++++++++++++++++++++++++---------
> 3 files changed, 35 insertions(+), 10 deletions(-)
>
> diff --git a/include/libmnl/libmnl.h b/include/libmnl/libmnl.h
> index 3a589bc..5adb13c 100644
> --- a/include/libmnl/libmnl.h
> +++ b/include/libmnl/libmnl.h
> @@ -21,7 +21,8 @@ extern "C" {
>
> struct mnl_socket;
>
> -extern struct mnl_socket *mnl_socket_open(int type);
> +extern struct mnl_socket *mnl_socket_open(int bus);
> +extern struct mnl_socket *mnl_socket_open2(int bus, int flags);
Looks good, but we should be using 'unsigned int flags' instead, right?
Or am I missing anything?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH libmnl 1/2] socket: introduce mnl_socket_open2()
2015-10-05 15:37 ` Pablo Neira Ayuso
@ 2015-10-05 16:33 ` Guillaume Nault
0 siblings, 0 replies; 11+ messages in thread
From: Guillaume Nault @ 2015-10-05 16:33 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: netfilter-devel
On Mon, Oct 05, 2015 at 05:37:15PM +0200, Pablo Neira Ayuso wrote:
> On Fri, Oct 02, 2015 at 10:12:33PM +0200, Guillaume Nault wrote:
> > Define mnl_socket_open2() so that user can pass a set of SOCK_* flags
> > at socket creation time.
> >
> > Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
> > ---
> > include/libmnl/libmnl.h | 3 ++-
> > src/libmnl.map | 1 +
> > src/socket.c | 41 ++++++++++++++++++++++++++++++++---------
> > 3 files changed, 35 insertions(+), 10 deletions(-)
> >
> > diff --git a/include/libmnl/libmnl.h b/include/libmnl/libmnl.h
> > index 3a589bc..5adb13c 100644
> > --- a/include/libmnl/libmnl.h
> > +++ b/include/libmnl/libmnl.h
> > @@ -21,7 +21,8 @@ extern "C" {
> >
> > struct mnl_socket;
> >
> > -extern struct mnl_socket *mnl_socket_open(int type);
> > +extern struct mnl_socket *mnl_socket_open(int bus);
> > +extern struct mnl_socket *mnl_socket_open2(int bus, int flags);
>
> Looks good, but we should be using 'unsigned int flags' instead, right?
>
> Or am I missing anything?
Generally speaking, I'd also consider unsigned integers to be more
appropriate for flag parameters.
But all socket() parameters are signed integers, including "type" which
is bitwise OR-ed with "flags". Furthermore, others libc's functions
introduced for the same purpose (race-free setting of CLOEXEC flag),
also use a signed integer as flag parameter (like dup3()).
So I've used int for consistency. But I can repost if you prefer.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH libmnl 1/2] socket: introduce mnl_socket_open2()
2015-10-02 20:12 ` [PATCH libmnl 1/2] socket: introduce mnl_socket_open2() Guillaume Nault
2015-10-05 15:37 ` Pablo Neira Ayuso
@ 2015-10-05 17:27 ` Jozsef Kadlecsik
2015-10-05 18:11 ` Pablo Neira Ayuso
2015-10-05 18:14 ` Guillaume Nault
2015-10-12 14:48 ` Pablo Neira Ayuso
2 siblings, 2 replies; 11+ messages in thread
From: Jozsef Kadlecsik @ 2015-10-05 17:27 UTC (permalink / raw)
To: Guillaume Nault; +Cc: netfilter-devel
Hi,
On Fri, 2 Oct 2015, Guillaume Nault wrote:
> Define mnl_socket_open2() so that user can pass a set of SOCK_* flags
> at socket creation time.
>
> Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
> ---
> include/libmnl/libmnl.h | 3 ++-
> src/libmnl.map | 1 +
> src/socket.c | 41 ++++++++++++++++++++++++++++++++---------
> 3 files changed, 35 insertions(+), 10 deletions(-)
>
> diff --git a/include/libmnl/libmnl.h b/include/libmnl/libmnl.h
> index 3a589bc..5adb13c 100644
> --- a/include/libmnl/libmnl.h
> +++ b/include/libmnl/libmnl.h
> @@ -21,7 +21,8 @@ extern "C" {
>
> struct mnl_socket;
>
> -extern struct mnl_socket *mnl_socket_open(int type);
> +extern struct mnl_socket *mnl_socket_open(int bus);
> +extern struct mnl_socket *mnl_socket_open2(int bus, int flags);
> extern struct mnl_socket *mnl_socket_fdopen(int fd);
> extern int mnl_socket_bind(struct mnl_socket *nl, unsigned int groups, pid_t pid);
> extern int mnl_socket_close(struct mnl_socket *nl);
> diff --git a/src/libmnl.map b/src/libmnl.map
> index 3c147a7..e5920e5 100644
> --- a/src/libmnl.map
> +++ b/src/libmnl.map
> @@ -74,5 +74,6 @@ LIBMNL_1.1 {
> } LIBMNL_1.0;
>
> LIBMNL_1.2 {
> + mnl_socket_open2;
> mnl_socket_fdopen;
> } LIBMNL_1.1;
I think this breaks library ABI: you should introduce a new revision
instead.
Best regards,
Jozsef
-
E-mail : kadlec@blackhole.kfki.hu, kadlecsik.jozsef@wigner.mta.hu
PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences
H-1525 Budapest 114, POB. 49, Hungary
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH libmnl 1/2] socket: introduce mnl_socket_open2()
2015-10-05 17:27 ` Jozsef Kadlecsik
@ 2015-10-05 18:11 ` Pablo Neira Ayuso
2015-10-05 18:38 ` Jozsef Kadlecsik
2015-10-05 18:14 ` Guillaume Nault
1 sibling, 1 reply; 11+ messages in thread
From: Pablo Neira Ayuso @ 2015-10-05 18:11 UTC (permalink / raw)
To: Jozsef Kadlecsik; +Cc: Guillaume Nault, netfilter-devel
On Mon, Oct 05, 2015 at 07:27:46PM +0200, Jozsef Kadlecsik wrote:
> Hi,
>
> On Fri, 2 Oct 2015, Guillaume Nault wrote:
>
> > Define mnl_socket_open2() so that user can pass a set of SOCK_* flags
> > at socket creation time.
> >
> > Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
> > ---
> > include/libmnl/libmnl.h | 3 ++-
> > src/libmnl.map | 1 +
> > src/socket.c | 41 ++++++++++++++++++++++++++++++++---------
> > 3 files changed, 35 insertions(+), 10 deletions(-)
> >
> > diff --git a/include/libmnl/libmnl.h b/include/libmnl/libmnl.h
> > index 3a589bc..5adb13c 100644
> > --- a/include/libmnl/libmnl.h
> > +++ b/include/libmnl/libmnl.h
> > @@ -21,7 +21,8 @@ extern "C" {
> >
> > struct mnl_socket;
> >
> > -extern struct mnl_socket *mnl_socket_open(int type);
> > +extern struct mnl_socket *mnl_socket_open(int bus);
> > +extern struct mnl_socket *mnl_socket_open2(int bus, int flags);
> > extern struct mnl_socket *mnl_socket_fdopen(int fd);
> > extern int mnl_socket_bind(struct mnl_socket *nl, unsigned int groups, pid_t pid);
> > extern int mnl_socket_close(struct mnl_socket *nl);
> > diff --git a/src/libmnl.map b/src/libmnl.map
> > index 3c147a7..e5920e5 100644
> > --- a/src/libmnl.map
> > +++ b/src/libmnl.map
> > @@ -74,5 +74,6 @@ LIBMNL_1.1 {
> > } LIBMNL_1.0;
> >
> > LIBMNL_1.2 {
> > + mnl_socket_open2;
> > mnl_socket_fdopen;
> > } LIBMNL_1.1;
>
> I think this breaks library ABI: you should introduce a new revision
> instead.
This would be part of the new interfaces for the next release:
diff --git a/src/libmnl.map b/src/libmnl.map
index dbc332e..e5920e5 100644
--- a/src/libmnl.map
+++ b/src/libmnl.map
@@ -72,3 +72,8 @@ local: *;
LIBMNL_1.1 {
mnl_attr_parse_payload;
} LIBMNL_1.0;
+
+LIBMNL_1.2 {
+ mnl_socket_open2;
+ mnl_socket_fdopen;
+} LIBMNL_1.1;
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH libmnl 1/2] socket: introduce mnl_socket_open2()
2015-10-05 17:27 ` Jozsef Kadlecsik
2015-10-05 18:11 ` Pablo Neira Ayuso
@ 2015-10-05 18:14 ` Guillaume Nault
2015-10-05 18:50 ` Jan Engelhardt
1 sibling, 1 reply; 11+ messages in thread
From: Guillaume Nault @ 2015-10-05 18:14 UTC (permalink / raw)
To: Jozsef Kadlecsik; +Cc: netfilter-devel
On Mon, Oct 05, 2015 at 07:27:46PM +0200, Jozsef Kadlecsik wrote:
> Hi,
>
> On Fri, 2 Oct 2015, Guillaume Nault wrote:
>
> > Define mnl_socket_open2() so that user can pass a set of SOCK_* flags
> > at socket creation time.
> >
> > Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
> > ---
> > include/libmnl/libmnl.h | 3 ++-
> > src/libmnl.map | 1 +
> > src/socket.c | 41 ++++++++++++++++++++++++++++++++---------
> > 3 files changed, 35 insertions(+), 10 deletions(-)
> >
> > diff --git a/include/libmnl/libmnl.h b/include/libmnl/libmnl.h
> > index 3a589bc..5adb13c 100644
> > --- a/include/libmnl/libmnl.h
> > +++ b/include/libmnl/libmnl.h
> > @@ -21,7 +21,8 @@ extern "C" {
> >
> > struct mnl_socket;
> >
> > -extern struct mnl_socket *mnl_socket_open(int type);
> > +extern struct mnl_socket *mnl_socket_open(int bus);
> > +extern struct mnl_socket *mnl_socket_open2(int bus, int flags);
> > extern struct mnl_socket *mnl_socket_fdopen(int fd);
> > extern int mnl_socket_bind(struct mnl_socket *nl, unsigned int groups, pid_t pid);
> > extern int mnl_socket_close(struct mnl_socket *nl);
> > diff --git a/src/libmnl.map b/src/libmnl.map
> > index 3c147a7..e5920e5 100644
> > --- a/src/libmnl.map
> > +++ b/src/libmnl.map
> > @@ -74,5 +74,6 @@ LIBMNL_1.1 {
> > } LIBMNL_1.0;
> >
> > LIBMNL_1.2 {
> > + mnl_socket_open2;
> > mnl_socket_fdopen;
> > } LIBMNL_1.1;
>
> I think this breaks library ABI: you should introduce a new revision
> instead.
>
AFAIK, this revision hasn't been part of any official release yet.
That's why I've exported mnl_socket_open2() there. I don't mind
incrementing the ABI version, but should we really do that for every
commit exporting a new function between two releases?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH libmnl 1/2] socket: introduce mnl_socket_open2()
2015-10-05 18:11 ` Pablo Neira Ayuso
@ 2015-10-05 18:38 ` Jozsef Kadlecsik
0 siblings, 0 replies; 11+ messages in thread
From: Jozsef Kadlecsik @ 2015-10-05 18:38 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: Guillaume Nault, netfilter-devel
On Mon, 5 Oct 2015, Pablo Neira Ayuso wrote:
> On Mon, Oct 05, 2015 at 07:27:46PM +0200, Jozsef Kadlecsik wrote:
> > Hi,
> >
> > On Fri, 2 Oct 2015, Guillaume Nault wrote:
> >
> > > Define mnl_socket_open2() so that user can pass a set of SOCK_* flags
> > > at socket creation time.
> > >
> > > Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
> > > ---
> > > include/libmnl/libmnl.h | 3 ++-
> > > src/libmnl.map | 1 +
> > > src/socket.c | 41 ++++++++++++++++++++++++++++++++---------
> > > 3 files changed, 35 insertions(+), 10 deletions(-)
> > >
> > > diff --git a/include/libmnl/libmnl.h b/include/libmnl/libmnl.h
> > > index 3a589bc..5adb13c 100644
> > > --- a/include/libmnl/libmnl.h
> > > +++ b/include/libmnl/libmnl.h
> > > @@ -21,7 +21,8 @@ extern "C" {
> > >
> > > struct mnl_socket;
> > >
> > > -extern struct mnl_socket *mnl_socket_open(int type);
> > > +extern struct mnl_socket *mnl_socket_open(int bus);
> > > +extern struct mnl_socket *mnl_socket_open2(int bus, int flags);
> > > extern struct mnl_socket *mnl_socket_fdopen(int fd);
> > > extern int mnl_socket_bind(struct mnl_socket *nl, unsigned int groups, pid_t pid);
> > > extern int mnl_socket_close(struct mnl_socket *nl);
> > > diff --git a/src/libmnl.map b/src/libmnl.map
> > > index 3c147a7..e5920e5 100644
> > > --- a/src/libmnl.map
> > > +++ b/src/libmnl.map
> > > @@ -74,5 +74,6 @@ LIBMNL_1.1 {
> > > } LIBMNL_1.0;
> > >
> > > LIBMNL_1.2 {
> > > + mnl_socket_open2;
> > > mnl_socket_fdopen;
> > > } LIBMNL_1.1;
> >
> > I think this breaks library ABI: you should introduce a new revision
> > instead.
>
> This would be part of the new interfaces for the next release:
That's right then, sorry for the noise :-)
Best regards,
Jozsef
> diff --git a/src/libmnl.map b/src/libmnl.map
> index dbc332e..e5920e5 100644
> --- a/src/libmnl.map
> +++ b/src/libmnl.map
> @@ -72,3 +72,8 @@ local: *;
> LIBMNL_1.1 {
> mnl_attr_parse_payload;
> } LIBMNL_1.0;
> +
> +LIBMNL_1.2 {
> + mnl_socket_open2;
> + mnl_socket_fdopen;
> +} LIBMNL_1.1;
>
> --
> To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
-
E-mail : kadlec@blackhole.kfki.hu, kadlecsik.jozsef@wigner.mta.hu
PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences
H-1525 Budapest 114, POB. 49, Hungary
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH libmnl 1/2] socket: introduce mnl_socket_open2()
2015-10-05 18:14 ` Guillaume Nault
@ 2015-10-05 18:50 ` Jan Engelhardt
0 siblings, 0 replies; 11+ messages in thread
From: Jan Engelhardt @ 2015-10-05 18:50 UTC (permalink / raw)
To: Guillaume Nault; +Cc: Jozsef Kadlecsik, netfilter-devel
On Monday 2015-10-05 20:14, Guillaume Nault wrote:
>>
>> I think this breaks library ABI: you should introduce a new revision
>> instead.
>>
>AFAIK, this revision hasn't been part of any official release yet.
>That's why I've exported mnl_socket_open2() there. I don't mind
>incrementing the ABI version, but should we really do that for every
>commit exporting a new function between two releases?
Not for every commit, indeed no. That would lead to a needlessy
larger (and deeper) symvers DAG, and therefore more to process for
dynamic and runtime linkers. Not much, but it would pile up
for x->\infty. This is also why the entire DAG should be flattened
again when setting -version-info C:R:A back to a new *:0:0.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH libmnl 1/2] socket: introduce mnl_socket_open2()
2015-10-02 20:12 ` [PATCH libmnl 1/2] socket: introduce mnl_socket_open2() Guillaume Nault
2015-10-05 15:37 ` Pablo Neira Ayuso
2015-10-05 17:27 ` Jozsef Kadlecsik
@ 2015-10-12 14:48 ` Pablo Neira Ayuso
2 siblings, 0 replies; 11+ messages in thread
From: Pablo Neira Ayuso @ 2015-10-12 14:48 UTC (permalink / raw)
To: Guillaume Nault; +Cc: netfilter-devel
On Fri, Oct 02, 2015 at 10:12:33PM +0200, Guillaume Nault wrote:
> Define mnl_socket_open2() so that user can pass a set of SOCK_* flags
> at socket creation time.
Applied, thanks for your patience.
Skipping patch 2/2 though.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2015-10-12 14:49 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-02 20:12 [PATCH libmnl 0/2] Introduce mnl_socket_open2() Guillaume Nault
2015-10-02 20:12 ` [PATCH libmnl 1/2] socket: introduce mnl_socket_open2() Guillaume Nault
2015-10-05 15:37 ` Pablo Neira Ayuso
2015-10-05 16:33 ` Guillaume Nault
2015-10-05 17:27 ` Jozsef Kadlecsik
2015-10-05 18:11 ` Pablo Neira Ayuso
2015-10-05 18:38 ` Jozsef Kadlecsik
2015-10-05 18:14 ` Guillaume Nault
2015-10-05 18:50 ` Jan Engelhardt
2015-10-12 14:48 ` Pablo Neira Ayuso
2015-10-02 20:12 ` [PATCH libmnl 2/2] examples: use mnl_socket_open2() Guillaume Nault
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).