|
|
049c96 |
From fc6ef05c8579a313461139e1c31130e0893c56f0 Mon Sep 17 00:00:00 2001
|
|
|
02706e |
From: Phil Sutter <psutter@redhat.com>
|
|
|
049c96 |
Date: Thu, 18 Feb 2016 14:06:06 +0100
|
|
|
02706e |
Subject: [PATCH] libnetlink: add size argument to rtnl_talk
|
|
|
02706e |
|
|
|
049c96 |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1288042
|
|
|
049c96 |
Upstream Status: iproute2.git commit c079e121a73af
|
|
|
049c96 |
Conflicts:
|
|
|
049c96 |
- Already applied commit d25ec03e1dce4
|
|
|
049c96 |
("ipaddress: fix ipaddr_flush for Linux >= 3.1").
|
|
|
049c96 |
- Missing commit 025fa9dc7a4fe
|
|
|
049c96 |
("xfrm: add command for configuring SPD hash table").
|
|
|
049c96 |
- Upstream conflict merge at 03371c7d98d16.
|
|
|
02706e |
|
|
|
02706e |
commit c079e121a73af5eb49e003b13607e8a690331df6
|
|
|
02706e |
Author: Stephen Hemminger <shemming@brocade.com>
|
|
|
02706e |
Date: Wed May 27 12:26:14 2015 -0700
|
|
|
02706e |
|
|
|
02706e |
libnetlink: add size argument to rtnl_talk
|
|
|
02706e |
|
|
|
02706e |
There have been several instances where response from kernel
|
|
|
02706e |
has overrun the stack buffer from the caller. Avoid future problems
|
|
|
02706e |
by passing a size argument.
|
|
|
02706e |
|
|
|
02706e |
Also drop the unused peer and group arguments to rtnl_talk.
|
|
|
02706e |
---
|
|
|
02706e |
bridge/fdb.c | 2 +-
|
|
|
02706e |
bridge/link.c | 2 +-
|
|
|
02706e |
bridge/mdb.c | 2 +-
|
|
|
02706e |
bridge/vlan.c | 2 +-
|
|
|
02706e |
genl/ctrl.c | 4 ++--
|
|
|
02706e |
include/libnetlink.h | 4 ++--
|
|
|
02706e |
ip/ipaddress.c | 4 ++--
|
|
|
02706e |
ip/ipaddrlabel.c | 4 ++--
|
|
|
02706e |
ip/ipl2tp.c | 8 ++++----
|
|
|
049c96 |
ip/iplink.c | 13 ++++++++-----
|
|
|
02706e |
ip/ipneigh.c | 2 +-
|
|
|
02706e |
ip/ipnetns.c | 4 ++--
|
|
|
02706e |
ip/ipntable.c | 2 +-
|
|
|
02706e |
ip/iproute.c | 8 ++++----
|
|
|
02706e |
ip/iprule.c | 4 ++--
|
|
|
02706e |
ip/iptoken.c | 2 +-
|
|
|
02706e |
ip/link_gre.c | 2 +-
|
|
|
02706e |
ip/link_gre6.c | 2 +-
|
|
|
02706e |
ip/link_ip6tnl.c | 2 +-
|
|
|
02706e |
ip/link_iptnl.c | 2 +-
|
|
|
02706e |
ip/link_vti.c | 2 +-
|
|
|
02706e |
ip/link_vti6.c | 2 +-
|
|
|
02706e |
ip/tcp_metrics.c | 4 ++--
|
|
|
02706e |
ip/xfrm_policy.c | 14 +++++++-------
|
|
|
02706e |
ip/xfrm_state.c | 12 ++++++------
|
|
|
02706e |
lib/libgenl.c | 2 +-
|
|
|
02706e |
lib/libnetlink.c | 40 ++++++++++++++++++++++------------------
|
|
|
02706e |
tc/m_action.c | 6 +++---
|
|
|
02706e |
tc/tc_class.c | 2 +-
|
|
|
02706e |
tc/tc_filter.c | 2 +-
|
|
|
02706e |
tc/tc_qdisc.c | 2 +-
|
|
|
049c96 |
31 files changed, 85 insertions(+), 78 deletions(-)
|
|
|
02706e |
|
|
|
02706e |
diff --git a/bridge/fdb.c b/bridge/fdb.c
|
|
|
049c96 |
index b8138cb..6dc3153 100644
|
|
|
02706e |
--- a/bridge/fdb.c
|
|
|
02706e |
+++ b/bridge/fdb.c
|
|
|
049c96 |
@@ -329,7 +329,7 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv)
|
|
|
02706e |
return -1;
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
049c96 |
return -1;
|
|
|
02706e |
|
|
|
02706e |
return 0;
|
|
|
02706e |
diff --git a/bridge/link.c b/bridge/link.c
|
|
|
049c96 |
index c5e7ae5..02777d6 100644
|
|
|
02706e |
--- a/bridge/link.c
|
|
|
02706e |
+++ b/bridge/link.c
|
|
|
049c96 |
@@ -376,7 +376,7 @@ static int brlink_modify(int argc, char **argv)
|
|
|
02706e |
addattr_nest_end(&req.n, nest);
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
049c96 |
return -1;
|
|
|
02706e |
|
|
|
02706e |
return 0;
|
|
|
02706e |
diff --git a/bridge/mdb.c b/bridge/mdb.c
|
|
|
049c96 |
index ab3a792..821f575 100644
|
|
|
02706e |
--- a/bridge/mdb.c
|
|
|
02706e |
+++ b/bridge/mdb.c
|
|
|
02706e |
@@ -224,7 +224,7 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
|
|
|
02706e |
|
|
|
02706e |
addattr_l(&req.n, sizeof(req), MDBA_SET_ENTRY, &entry, sizeof(entry));
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
049c96 |
return -1;
|
|
|
02706e |
|
|
|
02706e |
return 0;
|
|
|
02706e |
diff --git a/bridge/vlan.c b/bridge/vlan.c
|
|
|
049c96 |
index ba54b0e..b471bf7 100644
|
|
|
02706e |
--- a/bridge/vlan.c
|
|
|
02706e |
+++ b/bridge/vlan.c
|
|
|
02706e |
@@ -95,7 +95,7 @@ static int vlan_modify(int cmd, int argc, char **argv)
|
|
|
02706e |
|
|
|
02706e |
addattr_nest_end(&req.n, afspec);
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
049c96 |
return -1;
|
|
|
02706e |
|
|
|
02706e |
return 0;
|
|
|
02706e |
diff --git a/genl/ctrl.c b/genl/ctrl.c
|
|
|
049c96 |
index 48cbc35..2596883 100644
|
|
|
02706e |
--- a/genl/ctrl.c
|
|
|
02706e |
+++ b/genl/ctrl.c
|
|
|
02706e |
@@ -67,7 +67,7 @@ int genl_ctrl_resolve_family(const char *family)
|
|
|
02706e |
|
|
|
02706e |
addattr_l(nlh, 128, CTRL_ATTR_FAMILY_NAME, family, strlen(family) + 1);
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, nlh, 0, 0, nlh) < 0) {
|
|
|
02706e |
+ if (rtnl_talk(&rth, nlh, nlh, sizeof(req)) < 0) {
|
|
|
02706e |
fprintf(stderr, "Error talking to the kernel\n");
|
|
|
02706e |
goto errout;
|
|
|
02706e |
}
|
|
|
02706e |
@@ -341,7 +341,7 @@ static int ctrl_list(int cmd, int argc, char **argv)
|
|
|
02706e |
goto ctrl_done;
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, nlh, 0, 0, nlh) < 0) {
|
|
|
02706e |
+ if (rtnl_talk(&rth, nlh, nlh, sizeof(req)) < 0) {
|
|
|
02706e |
fprintf(stderr, "Error talking to the kernel\n");
|
|
|
02706e |
goto ctrl_done;
|
|
|
02706e |
}
|
|
|
02706e |
diff --git a/include/libnetlink.h b/include/libnetlink.h
|
|
|
049c96 |
index 058dc64..8c90873 100644
|
|
|
02706e |
--- a/include/libnetlink.h
|
|
|
02706e |
+++ b/include/libnetlink.h
|
|
|
049c96 |
@@ -68,8 +68,8 @@ int rtnl_dump_filter_nc(struct rtnl_handle *rth,
|
|
|
049c96 |
void *arg, __u16 nc_flags);
|
|
|
049c96 |
#define rtnl_dump_filter(rth, filter, arg) \
|
|
|
049c96 |
rtnl_dump_filter_nc(rth, filter, arg, 0)
|
|
|
02706e |
-extern int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
|
|
|
049c96 |
- unsigned groups, struct nlmsghdr *answer)
|
|
|
02706e |
+extern int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
|
|
|
049c96 |
+ struct nlmsghdr *answer, size_t len)
|
|
|
049c96 |
__attribute__((warn_unused_result));
|
|
|
049c96 |
extern int rtnl_send(struct rtnl_handle *rth, const void *buf, int)
|
|
|
049c96 |
__attribute__((warn_unused_result));
|
|
|
02706e |
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
|
|
|
049c96 |
index f5a47db..700c40f 100644
|
|
|
02706e |
--- a/ip/ipaddress.c
|
|
|
02706e |
+++ b/ip/ipaddress.c
|
|
|
049c96 |
@@ -1024,7 +1024,7 @@ static int restore_handler(const struct sockaddr_nl *nl,
|
|
|
02706e |
|
|
|
02706e |
ll_init_map(&rth);
|
|
|
02706e |
|
|
|
02706e |
- ret = rtnl_talk(&rth, n, 0, 0, n);
|
|
|
02706e |
+ ret = rtnl_talk(&rth, n, n, sizeof(*n));
|
|
|
02706e |
if ((ret < 0) && (errno == EEXIST))
|
|
|
02706e |
ret = 0;
|
|
|
02706e |
|
|
|
049c96 |
@@ -1587,7 +1587,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
|
|
|
02706e |
sizeof(cinfo));
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
02706e |
return -2;
|
|
|
02706e |
|
|
|
02706e |
return 0;
|
|
|
02706e |
diff --git a/ip/ipaddrlabel.c b/ip/ipaddrlabel.c
|
|
|
049c96 |
index 5b1f6e4..c5d69f4 100644
|
|
|
02706e |
--- a/ip/ipaddrlabel.c
|
|
|
02706e |
+++ b/ip/ipaddrlabel.c
|
|
|
049c96 |
@@ -183,7 +183,7 @@ static int ipaddrlabel_modify(int cmd, int argc, char **argv)
|
|
|
02706e |
if (req.ifal.ifal_family == AF_UNSPEC)
|
|
|
02706e |
req.ifal.ifal_family = AF_INET6;
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
049c96 |
return -2;
|
|
|
02706e |
|
|
|
02706e |
return 0;
|
|
|
049c96 |
@@ -210,7 +210,7 @@ static int flush_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, vo
|
|
|
02706e |
if (rtnl_open(&rth2, 0) < 0)
|
|
|
02706e |
return -1;
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth2, n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth2, n, NULL, 0) < 0)
|
|
|
02706e |
return -2;
|
|
|
02706e |
|
|
|
02706e |
rtnl_close(&rth2;;
|
|
|
02706e |
diff --git a/ip/ipl2tp.c b/ip/ipl2tp.c
|
|
|
049c96 |
index 5cd8632..2f7c9bf 100644
|
|
|
02706e |
--- a/ip/ipl2tp.c
|
|
|
02706e |
+++ b/ip/ipl2tp.c
|
|
|
02706e |
@@ -119,7 +119,7 @@ static int create_tunnel(struct l2tp_parm *p)
|
|
|
02706e |
addattr16(&req.n, 1024, L2TP_ATTR_UDP_DPORT, p->peer_udp_port);
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&genl_rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&genl_rth, &req.n, NULL, 0) < 0)
|
|
|
02706e |
return -2;
|
|
|
02706e |
|
|
|
02706e |
return 0;
|
|
|
02706e |
@@ -132,7 +132,7 @@ static int delete_tunnel(struct l2tp_parm *p)
|
|
|
02706e |
|
|
|
02706e |
addattr32(&req.n, 128, L2TP_ATTR_CONN_ID, p->tunnel_id);
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&genl_rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&genl_rth, &req.n, NULL, 0) < 0)
|
|
|
02706e |
return -2;
|
|
|
02706e |
|
|
|
02706e |
return 0;
|
|
|
02706e |
@@ -166,7 +166,7 @@ static int create_session(struct l2tp_parm *p)
|
|
|
02706e |
if (p->ifname && p->ifname[0])
|
|
|
02706e |
addattrstrz(&req.n, 1024, L2TP_ATTR_IFNAME, p->ifname);
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&genl_rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&genl_rth, &req.n, NULL, 0) < 0)
|
|
|
02706e |
return -2;
|
|
|
02706e |
|
|
|
02706e |
return 0;
|
|
|
02706e |
@@ -179,7 +179,7 @@ static int delete_session(struct l2tp_parm *p)
|
|
|
02706e |
|
|
|
02706e |
addattr32(&req.n, 1024, L2TP_ATTR_CONN_ID, p->tunnel_id);
|
|
|
02706e |
addattr32(&req.n, 1024, L2TP_ATTR_SESSION_ID, p->session_id);
|
|
|
02706e |
- if (rtnl_talk(&genl_rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&genl_rth, &req.n, NULL, 0) < 0)
|
|
|
02706e |
return -2;
|
|
|
02706e |
|
|
|
02706e |
return 0;
|
|
|
02706e |
diff --git a/ip/iplink.c b/ip/iplink.c
|
|
|
049c96 |
index 9362e83..048d4f3 100644
|
|
|
02706e |
--- a/ip/iplink.c
|
|
|
02706e |
+++ b/ip/iplink.c
|
|
|
049c96 |
@@ -592,7 +592,7 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
|
|
|
02706e |
|
|
|
02706e |
req.i.ifi_index = 0;
|
|
|
02706e |
addattr32(&req.n, sizeof(req), IFLA_GROUP, group);
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
02706e |
exit(2);
|
|
|
02706e |
return 0;
|
|
|
02706e |
}
|
|
|
049c96 |
@@ -667,7 +667,7 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
|
|
|
02706e |
return -1;
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
02706e |
exit(2);
|
|
|
02706e |
|
|
|
02706e |
return 0;
|
|
|
049c96 |
@@ -677,7 +677,10 @@ int iplink_get(unsigned int flags, char *name, __u32 filt_mask)
|
|
|
049c96 |
{
|
|
|
049c96 |
int len;
|
|
|
049c96 |
struct iplink_req req;
|
|
|
049c96 |
- char answer[16384];
|
|
|
049c96 |
+ struct {
|
|
|
049c96 |
+ struct nlmsghdr n;
|
|
|
049c96 |
+ char buf[16384];
|
|
|
049c96 |
+ } answer;
|
|
|
049c96 |
|
|
|
049c96 |
memset(&req, 0, sizeof(req));
|
|
|
049c96 |
|
|
|
049c96 |
@@ -697,10 +700,10 @@ int iplink_get(unsigned int flags, char *name, __u32 filt_mask)
|
|
|
049c96 |
}
|
|
|
049c96 |
addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask);
|
|
|
049c96 |
|
|
|
049c96 |
- if (rtnl_talk(&rth, &req.n, 0, 0, (struct nlmsghdr *)answer) < 0)
|
|
|
049c96 |
+ if (rtnl_talk(&rth, &req.n, &answer.n, sizeof(answer)) < 0)
|
|
|
049c96 |
return -2;
|
|
|
049c96 |
|
|
|
049c96 |
- print_linkinfo(NULL, (struct nlmsghdr *)answer, stdout);
|
|
|
049c96 |
+ print_linkinfo(NULL, &answer.n, stdout);
|
|
|
049c96 |
|
|
|
049c96 |
return 0;
|
|
|
049c96 |
}
|
|
|
02706e |
diff --git a/ip/ipneigh.c b/ip/ipneigh.c
|
|
|
049c96 |
index c47f005..19fd8e2 100644
|
|
|
02706e |
--- a/ip/ipneigh.c
|
|
|
02706e |
+++ b/ip/ipneigh.c
|
|
|
049c96 |
@@ -179,7 +179,7 @@ static int ipneigh_modify(int cmd, int flags, int argc, char **argv)
|
|
|
02706e |
return -1;
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
02706e |
exit(2);
|
|
|
02706e |
|
|
|
02706e |
return 0;
|
|
|
02706e |
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
|
|
|
049c96 |
index 00b6cc4..2c848bc 100644
|
|
|
02706e |
--- a/ip/ipnetns.c
|
|
|
02706e |
+++ b/ip/ipnetns.c
|
|
|
02706e |
@@ -113,7 +113,7 @@ static int get_netnsid_from_name(const char *name)
|
|
|
02706e |
return fd;
|
|
|
02706e |
|
|
|
02706e |
addattr32(&req.n, 1024, NETNSA_FD, fd);
|
|
|
02706e |
- if (rtnl_talk(&rtnsh, &req.n, 0, 0, &answer.n) < 0) {
|
|
|
02706e |
+ if (rtnl_talk(&rtnsh, &req.n, &answer.n, sizeof(answer)) < 0) {
|
|
|
02706e |
close(fd);
|
|
|
02706e |
return -2;
|
|
|
02706e |
}
|
|
|
02706e |
@@ -698,7 +698,7 @@ static int set_netnsid_from_name(const char *name, int nsid)
|
|
|
02706e |
|
|
|
02706e |
addattr32(&req.n, 1024, NETNSA_FD, fd);
|
|
|
02706e |
addattr32(&req.n, 1024, NETNSA_NSID, nsid);
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
02706e |
err = -2;
|
|
|
02706e |
|
|
|
02706e |
close(fd);
|
|
|
02706e |
diff --git a/ip/ipntable.c b/ip/ipntable.c
|
|
|
049c96 |
index 4d4eece..ca5d935 100644
|
|
|
02706e |
--- a/ip/ipntable.c
|
|
|
02706e |
+++ b/ip/ipntable.c
|
|
|
049c96 |
@@ -314,7 +314,7 @@ static int ipntable_modify(int cmd, int flags, int argc, char **argv)
|
|
|
02706e |
RTA_PAYLOAD(parms_rta));
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
02706e |
exit(2);
|
|
|
02706e |
|
|
|
02706e |
return 0;
|
|
|
02706e |
diff --git a/ip/iproute.c b/ip/iproute.c
|
|
|
049c96 |
index 4f7cd9b..367b922 100644
|
|
|
02706e |
--- a/ip/iproute.c
|
|
|
02706e |
+++ b/ip/iproute.c
|
|
|
02706e |
@@ -1029,7 +1029,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
|
|
|
02706e |
if (req.r.rtm_family == AF_UNSPEC)
|
|
|
02706e |
req.r.rtm_family = AF_INET;
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
049c96 |
return -2;
|
|
|
02706e |
|
|
|
02706e |
return 0;
|
|
|
02706e |
@@ -1486,7 +1486,7 @@ static int iproute_get(int argc, char **argv)
|
|
|
02706e |
if (req.r.rtm_family == AF_UNSPEC)
|
|
|
02706e |
req.r.rtm_family = AF_INET;
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, &req.n) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0)
|
|
|
02706e |
exit(2);
|
|
|
02706e |
|
|
|
02706e |
if (connected && !from_ok) {
|
|
|
02706e |
@@ -1527,7 +1527,7 @@ static int iproute_get(int argc, char **argv)
|
|
|
02706e |
req.n.nlmsg_flags = NLM_F_REQUEST;
|
|
|
02706e |
req.n.nlmsg_type = RTM_GETROUTE;
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, &req.n) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0)
|
|
|
02706e |
exit(2);
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
02706e |
@@ -1549,7 +1549,7 @@ static int restore_handler(const struct sockaddr_nl *nl,
|
|
|
02706e |
|
|
|
02706e |
ll_init_map(&rth);
|
|
|
02706e |
|
|
|
02706e |
- ret = rtnl_talk(&rth, n, 0, 0, n);
|
|
|
02706e |
+ ret = rtnl_talk(&rth, n, n, sizeof(*n));
|
|
|
02706e |
if ((ret < 0) && (errno == EEXIST))
|
|
|
02706e |
ret = 0;
|
|
|
02706e |
|
|
|
02706e |
diff --git a/ip/iprule.c b/ip/iprule.c
|
|
|
049c96 |
index eebcda2..89fa7ef 100644
|
|
|
02706e |
--- a/ip/iprule.c
|
|
|
02706e |
+++ b/ip/iprule.c
|
|
|
049c96 |
@@ -354,7 +354,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
|
|
|
02706e |
if (!table_ok && cmd == RTM_NEWRULE)
|
|
|
02706e |
req.r.rtm_table = RT_TABLE_MAIN;
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
049c96 |
return -2;
|
|
|
02706e |
|
|
|
02706e |
return 0;
|
|
|
049c96 |
@@ -381,7 +381,7 @@ static int flush_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *a
|
|
|
02706e |
if (rtnl_open(&rth2, 0) < 0)
|
|
|
02706e |
return -1;
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth2, n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth2, n, NULL, 0) < 0)
|
|
|
02706e |
return -2;
|
|
|
02706e |
|
|
|
02706e |
rtnl_close(&rth2;;
|
|
|
02706e |
diff --git a/ip/iptoken.c b/ip/iptoken.c
|
|
|
049c96 |
index 5689c2e..0d265e6 100644
|
|
|
02706e |
--- a/ip/iptoken.c
|
|
|
02706e |
+++ b/ip/iptoken.c
|
|
|
02706e |
@@ -182,7 +182,7 @@ static int iptoken_set(int argc, char **argv)
|
|
|
02706e |
return -1;
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
02706e |
return -2;
|
|
|
02706e |
|
|
|
02706e |
return 0;
|
|
|
02706e |
diff --git a/ip/link_gre.c b/ip/link_gre.c
|
|
|
049c96 |
index ddbd6cc..62acf46 100644
|
|
|
02706e |
--- a/ip/link_gre.c
|
|
|
02706e |
+++ b/ip/link_gre.c
|
|
|
049c96 |
@@ -77,7 +77,7 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
|
|
|
02706e |
req.i.ifi_family = preferred_family;
|
|
|
02706e |
req.i.ifi_index = ifi->ifi_index;
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, &req.n) < 0) {
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
|
|
|
02706e |
get_failed:
|
|
|
02706e |
fprintf(stderr,
|
|
|
02706e |
"Failed to get existing tunnel info.\n");
|
|
|
02706e |
diff --git a/ip/link_gre6.c b/ip/link_gre6.c
|
|
|
049c96 |
index f18919c..e00ea09 100644
|
|
|
02706e |
--- a/ip/link_gre6.c
|
|
|
02706e |
+++ b/ip/link_gre6.c
|
|
|
049c96 |
@@ -91,7 +91,7 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
|
|
|
02706e |
req.i.ifi_family = preferred_family;
|
|
|
02706e |
req.i.ifi_index = ifi->ifi_index;
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, &req.n) < 0) {
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
|
|
|
02706e |
get_failed:
|
|
|
02706e |
fprintf(stderr,
|
|
|
02706e |
"Failed to get existing tunnel info.\n");
|
|
|
02706e |
diff --git a/ip/link_ip6tnl.c b/ip/link_ip6tnl.c
|
|
|
049c96 |
index cf59a93..f771c75 100644
|
|
|
02706e |
--- a/ip/link_ip6tnl.c
|
|
|
02706e |
+++ b/ip/link_ip6tnl.c
|
|
|
049c96 |
@@ -89,7 +89,7 @@ static int ip6tunnel_parse_opt(struct link_util *lu, int argc, char **argv,
|
|
|
02706e |
req.i.ifi_family = preferred_family;
|
|
|
02706e |
req.i.ifi_index = ifi->ifi_index;
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, &req.n) < 0) {
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
|
|
|
02706e |
get_failed:
|
|
|
02706e |
fprintf(stderr,
|
|
|
02706e |
"Failed to get existing tunnel info.\n");
|
|
|
02706e |
diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c
|
|
|
049c96 |
index 2ac2604..4d5422b 100644
|
|
|
02706e |
--- a/ip/link_iptnl.c
|
|
|
02706e |
+++ b/ip/link_iptnl.c
|
|
|
049c96 |
@@ -81,7 +81,7 @@ static int iptunnel_parse_opt(struct link_util *lu, int argc, char **argv,
|
|
|
02706e |
req.i.ifi_family = preferred_family;
|
|
|
02706e |
req.i.ifi_index = ifi->ifi_index;
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, &req.n) < 0) {
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
|
|
|
02706e |
get_failed:
|
|
|
02706e |
fprintf(stderr,
|
|
|
02706e |
"Failed to get existing tunnel info.\n");
|
|
|
02706e |
diff --git a/ip/link_vti.c b/ip/link_vti.c
|
|
|
049c96 |
index 59ac4c4..f3fea33 100644
|
|
|
02706e |
--- a/ip/link_vti.c
|
|
|
02706e |
+++ b/ip/link_vti.c
|
|
|
049c96 |
@@ -71,7 +71,7 @@ static int vti_parse_opt(struct link_util *lu, int argc, char **argv,
|
|
|
02706e |
req.i.ifi_family = preferred_family;
|
|
|
02706e |
req.i.ifi_index = ifi->ifi_index;
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, &req.n) < 0) {
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
|
|
|
02706e |
get_failed:
|
|
|
02706e |
fprintf(stderr,
|
|
|
02706e |
"Failed to get existing tunnel info.\n");
|
|
|
02706e |
diff --git a/ip/link_vti6.c b/ip/link_vti6.c
|
|
|
049c96 |
index 282896d..c146f79 100644
|
|
|
02706e |
--- a/ip/link_vti6.c
|
|
|
02706e |
+++ b/ip/link_vti6.c
|
|
|
02706e |
@@ -67,7 +67,7 @@ static int vti6_parse_opt(struct link_util *lu, int argc, char **argv,
|
|
|
02706e |
req.i.ifi_family = preferred_family;
|
|
|
02706e |
req.i.ifi_index = ifi->ifi_index;
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, &req.n) < 0) {
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
|
|
|
02706e |
get_failed:
|
|
|
02706e |
fprintf(stderr,
|
|
|
02706e |
"Failed to get existing tunnel info.\n");
|
|
|
02706e |
diff --git a/ip/tcp_metrics.c b/ip/tcp_metrics.c
|
|
|
049c96 |
index c6be3c9..8fa4b26 100644
|
|
|
02706e |
--- a/ip/tcp_metrics.c
|
|
|
02706e |
+++ b/ip/tcp_metrics.c
|
|
|
02706e |
@@ -386,10 +386,10 @@ static int tcpm_do_cmd(int cmd, int argc, char **argv)
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
02706e |
if (ack) {
|
|
|
02706e |
- if (rtnl_talk(&grth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&grth, &req.n, NULL, 0) < 0)
|
|
|
02706e |
return -2;
|
|
|
02706e |
} else if (atype >= 0) {
|
|
|
02706e |
- if (rtnl_talk(&grth, &req.n, 0, 0, &req.n) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&grth, &req.n, &req.n, sizeof(req)) < 0)
|
|
|
02706e |
return -2;
|
|
|
02706e |
if (process_msg(NULL, &req.n, stdout) < 0) {
|
|
|
02706e |
fprintf(stderr, "Dump terminated\n");
|
|
|
02706e |
diff --git a/ip/xfrm_policy.c b/ip/xfrm_policy.c
|
|
|
049c96 |
index f7f2c5c..3ff734e 100644
|
|
|
02706e |
--- a/ip/xfrm_policy.c
|
|
|
02706e |
+++ b/ip/xfrm_policy.c
|
|
|
049c96 |
@@ -393,7 +393,7 @@ static int xfrm_policy_modify(int cmd, unsigned flags, int argc, char **argv)
|
|
|
02706e |
if (req.xpinfo.sel.family == AF_UNSPEC)
|
|
|
02706e |
req.xpinfo.sel.family = AF_INET;
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
02706e |
exit(2);
|
|
|
02706e |
|
|
|
02706e |
rtnl_close(&rth);
|
|
|
049c96 |
@@ -555,7 +555,7 @@ int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
02706e |
static int xfrm_policy_get_or_delete(int argc, char **argv, int delete,
|
|
|
02706e |
- void *res_nlbuf)
|
|
|
02706e |
+ void *res_nlbuf, size_t res_size)
|
|
|
02706e |
{
|
|
|
02706e |
struct rtnl_handle rth;
|
|
|
02706e |
struct {
|
|
|
049c96 |
@@ -670,7 +670,7 @@ static int xfrm_policy_get_or_delete(int argc, char **argv, int delete,
|
|
|
02706e |
(void *)&ctx, ctx.sctx.len);
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, res_nlbuf) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, res_nlbuf, res_size) < 0)
|
|
|
02706e |
exit(2);
|
|
|
02706e |
|
|
|
02706e |
rtnl_close(&rth);
|
|
|
049c96 |
@@ -680,7 +680,7 @@ static int xfrm_policy_get_or_delete(int argc, char **argv, int delete,
|
|
|
02706e |
|
|
|
02706e |
static int xfrm_policy_delete(int argc, char **argv)
|
|
|
02706e |
{
|
|
|
02706e |
- return xfrm_policy_get_or_delete(argc, argv, 1, NULL);
|
|
|
02706e |
+ return xfrm_policy_get_or_delete(argc, argv, 1, NULL, 0);
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
02706e |
static int xfrm_policy_get(int argc, char **argv)
|
|
|
049c96 |
@@ -690,7 +690,7 @@ static int xfrm_policy_get(int argc, char **argv)
|
|
|
02706e |
|
|
|
02706e |
memset(buf, 0, sizeof(buf));
|
|
|
02706e |
|
|
|
02706e |
- xfrm_policy_get_or_delete(argc, argv, 0, n);
|
|
|
02706e |
+ xfrm_policy_get_or_delete(argc, argv, 0, n, sizeof(buf));
|
|
|
02706e |
|
|
|
02706e |
if (xfrm_policy_print(NULL, n, (void*)stdout) < 0) {
|
|
|
02706e |
fprintf(stderr, "An error :-)\n");
|
|
|
049c96 |
@@ -975,7 +975,7 @@ static int xfrm_spd_getinfo(int argc, char **argv)
|
|
|
02706e |
if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0)
|
|
|
02706e |
exit(1);
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, &req.n) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0)
|
|
|
02706e |
exit(2);
|
|
|
02706e |
|
|
|
02706e |
print_spdinfo(&req.n, (void*)stdout);
|
|
|
049c96 |
@@ -1027,7 +1027,7 @@ static int xfrm_policy_flush(int argc, char **argv)
|
|
|
02706e |
if (show_stats > 1)
|
|
|
02706e |
fprintf(stderr, "Flush policy\n");
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
02706e |
exit(2);
|
|
|
02706e |
|
|
|
02706e |
rtnl_close(&rth);
|
|
|
02706e |
diff --git a/ip/xfrm_state.c b/ip/xfrm_state.c
|
|
|
049c96 |
index 0f6b10d..20d7a7e 100644
|
|
|
02706e |
--- a/ip/xfrm_state.c
|
|
|
02706e |
+++ b/ip/xfrm_state.c
|
|
|
049c96 |
@@ -644,7 +644,7 @@ static int xfrm_state_modify(int cmd, unsigned flags, int argc, char **argv)
|
|
|
02706e |
if (req.xsinfo.family == AF_UNSPEC)
|
|
|
02706e |
req.xsinfo.family = AF_INET;
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
02706e |
exit(2);
|
|
|
02706e |
|
|
|
02706e |
rtnl_close(&rth);
|
|
|
049c96 |
@@ -781,7 +781,7 @@ static int xfrm_state_allocspi(int argc, char **argv)
|
|
|
02706e |
req.xspi.info.family = AF_INET;
|
|
|
02706e |
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, res_n) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, res_n, sizeof(res_buf)) < 0)
|
|
|
02706e |
exit(2);
|
|
|
02706e |
|
|
|
02706e |
if (xfrm_state_print(NULL, res_n, (void*)stdout) < 0) {
|
|
|
049c96 |
@@ -971,7 +971,7 @@ static int xfrm_state_get_or_delete(int argc, char **argv, int delete)
|
|
|
02706e |
req.xsid.family = AF_INET;
|
|
|
02706e |
|
|
|
02706e |
if (delete) {
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
02706e |
exit(2);
|
|
|
02706e |
} else {
|
|
|
02706e |
char buf[NLMSG_BUF_SIZE];
|
|
|
049c96 |
@@ -979,7 +979,7 @@ static int xfrm_state_get_or_delete(int argc, char **argv, int delete)
|
|
|
02706e |
|
|
|
02706e |
memset(buf, 0, sizeof(buf));
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, res_n) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, res_n, sizeof(req)) < 0)
|
|
|
02706e |
exit(2);
|
|
|
02706e |
|
|
|
02706e |
if (xfrm_state_print(NULL, res_n, (void*)stdout) < 0) {
|
|
|
049c96 |
@@ -1220,7 +1220,7 @@ static int xfrm_sad_getinfo(int argc, char **argv)
|
|
|
02706e |
if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0)
|
|
|
02706e |
exit(1);
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, &req.n) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0)
|
|
|
02706e |
exit(2);
|
|
|
02706e |
|
|
|
02706e |
print_sadinfo(&req.n, (void*)stdout);
|
|
|
049c96 |
@@ -1274,7 +1274,7 @@ static int xfrm_state_flush(int argc, char **argv)
|
|
|
02706e |
fprintf(stderr, "Flush state with XFRM-PROTO value \"%s\"\n",
|
|
|
02706e |
strxf_xfrmproto(req.xsf.proto));
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
02706e |
exit(2);
|
|
|
02706e |
|
|
|
02706e |
rtnl_close(&rth);
|
|
|
02706e |
diff --git a/lib/libgenl.c b/lib/libgenl.c
|
|
|
049c96 |
index ef3e5db..acb1478 100644
|
|
|
02706e |
--- a/lib/libgenl.c
|
|
|
02706e |
+++ b/lib/libgenl.c
|
|
|
02706e |
@@ -53,7 +53,7 @@ int genl_resolve_family(struct rtnl_handle *grth, const char *family)
|
|
|
02706e |
addattr_l(&req.n, sizeof(req), CTRL_ATTR_FAMILY_NAME,
|
|
|
02706e |
family, strlen(family) + 1);
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(grth, &req.n, 0, 0, &req.n) < 0) {
|
|
|
02706e |
+ if (rtnl_talk(grth, &req.n, &req.n, sizeof(req)) < 0) {
|
|
|
02706e |
fprintf(stderr, "Error talking to the kernel\n");
|
|
|
02706e |
return -2;
|
|
|
02706e |
}
|
|
|
02706e |
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
|
|
|
049c96 |
index 95675be..97b79fd 100644
|
|
|
02706e |
--- a/lib/libnetlink.c
|
|
|
02706e |
+++ b/lib/libnetlink.c
|
|
|
02706e |
@@ -29,6 +29,10 @@
|
|
|
02706e |
#define SOL_NETLINK 270
|
|
|
02706e |
#endif
|
|
|
02706e |
|
|
|
02706e |
+#ifndef MIN
|
|
|
02706e |
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
|
02706e |
+#endif
|
|
|
02706e |
+
|
|
|
02706e |
int rcvbuf = 1024 * 1024;
|
|
|
02706e |
|
|
|
02706e |
void rtnl_close(struct rtnl_handle *rth)
|
|
|
049c96 |
@@ -306,8 +310,8 @@ int rtnl_dump_filter_nc(struct rtnl_handle *rth,
|
|
|
02706e |
return rtnl_dump_filter_l(rth, a);
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
02706e |
-int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
|
|
|
02706e |
- unsigned groups, struct nlmsghdr *answer)
|
|
|
02706e |
+int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
|
|
|
049c96 |
+ struct nlmsghdr *answer, size_t len)
|
|
|
02706e |
{
|
|
|
02706e |
int status;
|
|
|
02706e |
unsigned seq;
|
|
|
049c96 |
@@ -323,12 +327,10 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
|
|
|
02706e |
.msg_iov = &iov,
|
|
|
02706e |
.msg_iovlen = 1,
|
|
|
02706e |
};
|
|
|
02706e |
- char buf[16384];
|
|
|
02706e |
+ char buf[32768];
|
|
|
02706e |
|
|
|
02706e |
memset(&nladdr, 0, sizeof(nladdr));
|
|
|
02706e |
nladdr.nl_family = AF_NETLINK;
|
|
|
02706e |
- nladdr.nl_pid = peer;
|
|
|
02706e |
- nladdr.nl_groups = groups;
|
|
|
02706e |
|
|
|
02706e |
n->nlmsg_seq = seq = ++rtnl->seq;
|
|
|
02706e |
|
|
|
049c96 |
@@ -336,7 +338,6 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
|
|
|
02706e |
n->nlmsg_flags |= NLM_F_ACK;
|
|
|
02706e |
|
|
|
02706e |
status = sendmsg(rtnl->fd, &msg, 0);
|
|
|
02706e |
-
|
|
|
02706e |
if (status < 0) {
|
|
|
02706e |
perror("Cannot talk to rtnetlink");
|
|
|
02706e |
return -1;
|
|
|
049c96 |
@@ -345,7 +346,6 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
|
|
|
02706e |
memset(buf,0,sizeof(buf));
|
|
|
02706e |
|
|
|
02706e |
iov.iov_base = buf;
|
|
|
02706e |
-
|
|
|
02706e |
while (1) {
|
|
|
02706e |
iov.iov_len = sizeof(buf);
|
|
|
02706e |
status = recvmsg(rtnl->fd, &msg, 0);
|
|
|
049c96 |
@@ -378,7 +378,7 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
|
|
|
02706e |
exit(1);
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
02706e |
- if (nladdr.nl_pid != peer ||
|
|
|
02706e |
+ if (nladdr.nl_pid != 0 ||
|
|
|
02706e |
h->nlmsg_pid != rtnl->local.nl_pid ||
|
|
|
02706e |
h->nlmsg_seq != seq) {
|
|
|
02706e |
/* Don't forget to skip that message. */
|
|
|
049c96 |
@@ -391,20 +391,22 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
|
|
|
02706e |
struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h);
|
|
|
02706e |
if (l < sizeof(struct nlmsgerr)) {
|
|
|
02706e |
fprintf(stderr, "ERROR truncated\n");
|
|
|
02706e |
- } else {
|
|
|
02706e |
- if (!err->error) {
|
|
|
02706e |
- if (answer)
|
|
|
02706e |
- memcpy(answer, h, h->nlmsg_len);
|
|
|
02706e |
- return 0;
|
|
|
02706e |
- }
|
|
|
02706e |
-
|
|
|
02706e |
- fprintf(stderr, "RTNETLINK answers: %s\n", strerror(-err->error));
|
|
|
02706e |
- errno = -err->error;
|
|
|
02706e |
+ } else if (!err->error) {
|
|
|
02706e |
+ if (answer)
|
|
|
02706e |
+ memcpy(answer, h,
|
|
|
049c96 |
+ MIN(len, h->nlmsg_len));
|
|
|
02706e |
+ return 0;
|
|
|
02706e |
}
|
|
|
02706e |
+
|
|
|
02706e |
+ fprintf(stderr, "RTNETLINK answers: %s\n",
|
|
|
02706e |
+ strerror(-err->error));
|
|
|
02706e |
+ errno = -err->error;
|
|
|
02706e |
return -1;
|
|
|
02706e |
}
|
|
|
02706e |
+
|
|
|
02706e |
if (answer) {
|
|
|
02706e |
- memcpy(answer, h, h->nlmsg_len);
|
|
|
02706e |
+ memcpy(answer, h,
|
|
|
049c96 |
+ MIN(len, h->nlmsg_len));
|
|
|
02706e |
return 0;
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
049c96 |
@@ -413,10 +415,12 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
|
|
|
02706e |
status -= NLMSG_ALIGN(len);
|
|
|
02706e |
h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len));
|
|
|
02706e |
}
|
|
|
02706e |
+
|
|
|
02706e |
if (msg.msg_flags & MSG_TRUNC) {
|
|
|
02706e |
fprintf(stderr, "Message truncated\n");
|
|
|
02706e |
continue;
|
|
|
02706e |
}
|
|
|
02706e |
+
|
|
|
02706e |
if (status) {
|
|
|
02706e |
fprintf(stderr, "!!!Remnant of size %d\n", status);
|
|
|
02706e |
exit(1);
|
|
|
02706e |
diff --git a/tc/m_action.c b/tc/m_action.c
|
|
|
049c96 |
index 4acabef..7cbf377 100644
|
|
|
02706e |
--- a/tc/m_action.c
|
|
|
02706e |
+++ b/tc/m_action.c
|
|
|
02706e |
@@ -451,7 +451,7 @@ static int tc_action_gd(int cmd, unsigned flags, int *argc_p, char ***argv_p)
|
|
|
02706e |
if (cmd == RTM_GETACTION)
|
|
|
02706e |
ans = &req.n;
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, ans) < 0) {
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, ans, MAX_MSG) < 0) {
|
|
|
02706e |
fprintf(stderr, "We have an error talking to the kernel\n");
|
|
|
02706e |
return 1;
|
|
|
02706e |
}
|
|
|
02706e |
@@ -496,7 +496,7 @@ static int tc_action_modify(int cmd, unsigned flags, int *argc_p, char ***argv_p
|
|
|
02706e |
}
|
|
|
02706e |
tail->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail;
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0) {
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0) {
|
|
|
02706e |
fprintf(stderr, "We have an error talking to the kernel\n");
|
|
|
02706e |
ret = -1;
|
|
|
02706e |
}
|
|
|
02706e |
@@ -566,7 +566,7 @@ static int tc_act_list_or_flush(int argc, char **argv, int event)
|
|
|
02706e |
req.n.nlmsg_type = RTM_DELACTION;
|
|
|
02706e |
req.n.nlmsg_flags |= NLM_F_ROOT;
|
|
|
02706e |
req.n.nlmsg_flags |= NLM_F_REQUEST;
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0) {
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0) {
|
|
|
02706e |
fprintf(stderr, "We have an error flushing\n");
|
|
|
02706e |
return 1;
|
|
|
02706e |
}
|
|
|
02706e |
diff --git a/tc/tc_class.c b/tc/tc_class.c
|
|
|
049c96 |
index b8767bc..4f35346 100644
|
|
|
02706e |
--- a/tc/tc_class.c
|
|
|
02706e |
+++ b/tc/tc_class.c
|
|
|
02706e |
@@ -138,7 +138,7 @@ static int tc_class_modify(int cmd, unsigned flags, int argc, char **argv)
|
|
|
02706e |
}
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
02706e |
return 2;
|
|
|
02706e |
|
|
|
02706e |
return 0;
|
|
|
02706e |
diff --git a/tc/tc_filter.c b/tc/tc_filter.c
|
|
|
049c96 |
index 609fbe9..e76d616 100644
|
|
|
02706e |
--- a/tc/tc_filter.c
|
|
|
02706e |
+++ b/tc/tc_filter.c
|
|
|
02706e |
@@ -167,7 +167,7 @@ static int tc_filter_modify(int cmd, unsigned flags, int argc, char **argv)
|
|
|
02706e |
}
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0) {
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0) {
|
|
|
02706e |
fprintf(stderr, "We have an error talking to the kernel\n");
|
|
|
02706e |
return 2;
|
|
|
02706e |
}
|
|
|
02706e |
diff --git a/tc/tc_qdisc.c b/tc/tc_qdisc.c
|
|
|
049c96 |
index c71937d..c31ae8d 100644
|
|
|
02706e |
--- a/tc/tc_qdisc.c
|
|
|
02706e |
+++ b/tc/tc_qdisc.c
|
|
|
02706e |
@@ -187,7 +187,7 @@ static int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv)
|
|
|
02706e |
req.t.tcm_ifindex = idx;
|
|
|
02706e |
}
|
|
|
02706e |
|
|
|
02706e |
- if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
|
|
|
02706e |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
|
|
|
02706e |
return 2;
|
|
|
02706e |
|
|
|
02706e |
return 0;
|
|
|
02706e |
--
|
|
|
049c96 |
1.8.3.1
|
|
|
02706e |
|