|
|
4aca6e |
From 734c47bbe6a885923d52be91e8aaddfccaa182f5 Mon Sep 17 00:00:00 2001
|
|
|
4aca6e |
From: Timothy Redaelli <tredaelli@redhat.com>
|
|
|
4aca6e |
Date: Fri, 10 Feb 2017 12:51:08 +0100
|
|
|
4aca6e |
Subject: [PATCH] libgenl: introduce genl_init_handle
|
|
|
4aca6e |
|
|
|
4aca6e |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1367071
|
|
|
4aca6e |
Upstream Status: iproute2.git commit 2b68cb7
|
|
|
4aca6e |
Conflicts: ip/ipfou.c and ip/ipila.c files doesn't exists in our tree
|
|
|
4aca6e |
|
|
|
4aca6e |
commit 2b68cb77cde32f5cba5f984e15fc402758edea76
|
|
|
4aca6e |
Author: Sabrina Dubroca <sd@queasysnail.net>
|
|
|
4aca6e |
Date: Tue Aug 16 16:26:55 2016 +0200
|
|
|
4aca6e |
|
|
|
4aca6e |
libgenl: introduce genl_init_handle
|
|
|
4aca6e |
|
|
|
4aca6e |
All users of genl have the same code to open a genl socket and resolve
|
|
|
4aca6e |
the family for their specific protocol. Introduce a helper to initialize
|
|
|
4aca6e |
the handle, and use it in all the genl code.
|
|
|
4aca6e |
|
|
|
4aca6e |
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
|
|
|
4aca6e |
|
|
|
4aca6e |
Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>
|
|
|
4aca6e |
---
|
|
|
4aca6e |
include/libgenl.h | 2 ++
|
|
|
4aca6e |
ip/ipl2tp.c | 12 ++----------
|
|
|
4aca6e |
ip/ipmacsec.c | 18 ++----------------
|
|
|
4aca6e |
ip/tcp_metrics.c | 14 +++-----------
|
|
|
4aca6e |
lib/libgenl.c | 17 +++++++++++++++++
|
|
|
4aca6e |
5 files changed, 26 insertions(+), 37 deletions(-)
|
|
|
4aca6e |
|
|
|
4aca6e |
diff --git a/include/libgenl.h b/include/libgenl.h
|
|
|
4aca6e |
index 9db4baf..2dbb4b3 100644
|
|
|
4aca6e |
--- a/include/libgenl.h
|
|
|
4aca6e |
+++ b/include/libgenl.h
|
|
|
4aca6e |
@@ -21,5 +21,7 @@ struct { \
|
|
|
4aca6e |
}
|
|
|
4aca6e |
|
|
|
4aca6e |
extern int genl_resolve_family(struct rtnl_handle *grth, const char *family);
|
|
|
4aca6e |
+extern int genl_init_handle(struct rtnl_handle *grth, const char *family,
|
|
|
4aca6e |
+ int *genl_family);
|
|
|
4aca6e |
|
|
|
4aca6e |
#endif /* __LIBGENL_H__ */
|
|
|
4aca6e |
diff --git a/ip/ipl2tp.c b/ip/ipl2tp.c
|
|
|
4aca6e |
index d2c8979..ced4a8b 100644
|
|
|
4aca6e |
--- a/ip/ipl2tp.c
|
|
|
4aca6e |
+++ b/ip/ipl2tp.c
|
|
|
4aca6e |
@@ -711,16 +711,8 @@ int do_ipl2tp(int argc, char **argv)
|
|
|
4aca6e |
if (argc < 1 || !matches(*argv, "help"))
|
|
|
4aca6e |
usage();
|
|
|
4aca6e |
|
|
|
4aca6e |
- if (genl_family < 0) {
|
|
|
4aca6e |
- if (rtnl_open_byproto(&genl_rth, 0, NETLINK_GENERIC) < 0) {
|
|
|
4aca6e |
- fprintf(stderr, "Cannot open generic netlink socket\n");
|
|
|
4aca6e |
- exit(1);
|
|
|
4aca6e |
- }
|
|
|
4aca6e |
-
|
|
|
4aca6e |
- genl_family = genl_resolve_family(&genl_rth, L2TP_GENL_NAME);
|
|
|
4aca6e |
- if (genl_family < 0)
|
|
|
4aca6e |
- exit(1);
|
|
|
4aca6e |
- }
|
|
|
4aca6e |
+ if (genl_init_handle(&genl_rth, L2TP_GENL_NAME, &genl_family))
|
|
|
4aca6e |
+ exit(1);
|
|
|
4aca6e |
|
|
|
4aca6e |
if (matches(*argv, "add") == 0)
|
|
|
4aca6e |
return do_add(argc-1, argv+1);
|
|
|
4aca6e |
diff --git a/ip/ipmacsec.c b/ip/ipmacsec.c
|
|
|
4aca6e |
index 0c51bfc..f05b27a 100644
|
|
|
4aca6e |
--- a/ip/ipmacsec.c
|
|
|
4aca6e |
+++ b/ip/ipmacsec.c
|
|
|
4aca6e |
@@ -79,21 +79,6 @@ static int genl_family = -1;
|
|
|
4aca6e |
_cmd, _flags)
|
|
|
4aca6e |
|
|
|
4aca6e |
|
|
|
4aca6e |
-static void init_genl(void)
|
|
|
4aca6e |
-{
|
|
|
4aca6e |
- if (genl_family >= 0)
|
|
|
4aca6e |
- return;
|
|
|
4aca6e |
-
|
|
|
4aca6e |
- if (rtnl_open_byproto(&genl_rth, 0, NETLINK_GENERIC) < 0) {
|
|
|
4aca6e |
- fprintf(stderr, "Cannot open generic netlink socket\n");
|
|
|
4aca6e |
- exit(1);
|
|
|
4aca6e |
- }
|
|
|
4aca6e |
-
|
|
|
4aca6e |
- genl_family = genl_resolve_family(&genl_rth, MACSEC_GENL_NAME);
|
|
|
4aca6e |
- if (genl_family < 0)
|
|
|
4aca6e |
- exit(1);
|
|
|
4aca6e |
-}
|
|
|
4aca6e |
-
|
|
|
4aca6e |
static void ipmacsec_usage(void)
|
|
|
4aca6e |
{
|
|
|
4aca6e |
fprintf(stderr, "Usage: ip macsec add DEV tx sa { 0..3 } [ OPTS ] key ID KEY\n");
|
|
|
4aca6e |
@@ -1001,7 +986,8 @@ static int do_show(int argc, char **argv)
|
|
|
4aca6e |
|
|
|
4aca6e |
int do_ipmacsec(int argc, char **argv)
|
|
|
4aca6e |
{
|
|
|
4aca6e |
- init_genl();
|
|
|
4aca6e |
+ if (genl_init_handle(&genl_rth, MACSEC_GENL_NAME, &genl_family))
|
|
|
4aca6e |
+ exit(1);
|
|
|
4aca6e |
|
|
|
4aca6e |
if (argc < 1)
|
|
|
4aca6e |
ipmacsec_usage();
|
|
|
4aca6e |
diff --git a/ip/tcp_metrics.c b/ip/tcp_metrics.c
|
|
|
4aca6e |
index c55d9ad..b055288 100644
|
|
|
4aca6e |
--- a/ip/tcp_metrics.c
|
|
|
4aca6e |
+++ b/ip/tcp_metrics.c
|
|
|
4aca6e |
@@ -320,17 +320,9 @@ static int tcpm_do_cmd(int cmd, int argc, char **argv)
|
|
|
4aca6e |
ack = 0;
|
|
|
4aca6e |
}
|
|
|
4aca6e |
|
|
|
4aca6e |
- if (genl_family < 0) {
|
|
|
4aca6e |
- if (rtnl_open_byproto(&grth, 0, NETLINK_GENERIC) < 0) {
|
|
|
4aca6e |
- fprintf(stderr, "Cannot open generic netlink socket\n");
|
|
|
4aca6e |
- exit(1);
|
|
|
4aca6e |
- }
|
|
|
4aca6e |
- genl_family = genl_resolve_family(&grth,
|
|
|
4aca6e |
- TCP_METRICS_GENL_NAME);
|
|
|
4aca6e |
- if (genl_family < 0)
|
|
|
4aca6e |
- exit(1);
|
|
|
4aca6e |
- req.n.nlmsg_type = genl_family;
|
|
|
4aca6e |
- }
|
|
|
4aca6e |
+ if (genl_init_handle(&grth, TCP_METRICS_GENL_NAME, &genl_family))
|
|
|
4aca6e |
+ exit(1);
|
|
|
4aca6e |
+ req.n.nlmsg_type = genl_family;
|
|
|
4aca6e |
|
|
|
4aca6e |
if (!(cmd & CMD_FLUSH) && (atype >= 0 || (cmd & CMD_DEL))) {
|
|
|
4aca6e |
if (ack)
|
|
|
4aca6e |
diff --git a/lib/libgenl.c b/lib/libgenl.c
|
|
|
4aca6e |
index acb1478..50d2d92 100644
|
|
|
4aca6e |
--- a/lib/libgenl.c
|
|
|
4aca6e |
+++ b/lib/libgenl.c
|
|
|
4aca6e |
@@ -61,3 +61,20 @@ int genl_resolve_family(struct rtnl_handle *grth, const char *family)
|
|
|
4aca6e |
return genl_parse_getfamily(&req.n);
|
|
|
4aca6e |
}
|
|
|
4aca6e |
|
|
|
4aca6e |
+int genl_init_handle(struct rtnl_handle *grth, const char *family,
|
|
|
4aca6e |
+ int *genl_family)
|
|
|
4aca6e |
+{
|
|
|
4aca6e |
+ if (*genl_family >= 0)
|
|
|
4aca6e |
+ return 0;
|
|
|
4aca6e |
+
|
|
|
4aca6e |
+ if (rtnl_open_byproto(grth, 0, NETLINK_GENERIC) < 0) {
|
|
|
4aca6e |
+ fprintf(stderr, "Cannot open generic netlink socket\n");
|
|
|
4aca6e |
+ return -1;
|
|
|
4aca6e |
+ }
|
|
|
4aca6e |
+
|
|
|
4aca6e |
+ *genl_family = genl_resolve_family(grth, family);
|
|
|
4aca6e |
+ if (*genl_family < 0)
|
|
|
4aca6e |
+ return -1;
|
|
|
4aca6e |
+
|
|
|
4aca6e |
+ return 0;
|
|
|
4aca6e |
+}
|
|
|
4aca6e |
--
|
|
|
4aca6e |
1.8.3.1
|
|
|
4aca6e |
|