summaryrefslogtreecommitdiffstats
path: root/ip
diff options
context:
space:
mode:
authorSimon Horman <horms@verge.net.au>2009-12-03 12:08:27 +1100
committerStephen Hemminger <stephen.hemminger@vyatta.com>2009-12-26 10:11:02 -0800
commitb49240ec7eab91418d2f090536bf8cd2205988d6 (patch)
treec0647bb8c9bef3bc02a9d2877aa854314ec87732 /ip
parenta36ceb85d7ae6a9742c35417e80ae837ce9f146d (diff)
flush secondary addresses before primary ones
Unless promote_secondaries has been active deleting the primary address of an interface will automatically delete all the secondary addresses. In the case where ip flush requests the primary then secondary addresses to be removed - which is the order the addresses are returned by the kernel - this will cause an error as by the time the request to remove a secondary address is made it will be missing as it will have been deleted in the course of deleting the primary address. This approach to solving this problem orders requests for the deletion of secondary addresses before primary ones providing rtnl_dump_filter_l(), a version of rtnl_dump_filter() that iterates over a list of filters. And by providing two specialised filters print_addrinfo_secondary() and print_addrinfo_primary(). rtnl_dump_filter_l() first iterates over all addresses using print_addrinfo_secondary(), which appends secondary addresses to the request buffer. Then again using print_addrinfo_primary() which appends primary addresses. This approach should work regardless of it promote_secondaries is active or not. And regardless of if any primary of secondary addresses are present or not. Signed-off-by: Simon Horman <horms@verge.net.au>
Diffstat (limited to 'ip')
-rw-r--r--ip/ipaddress.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index f0add800..c638ca74 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -539,6 +539,27 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
return 0;
}
+int print_addrinfo_primary(const struct sockaddr_nl *who, struct nlmsghdr *n,
+ void *arg)
+{
+ struct ifaddrmsg *ifa = NLMSG_DATA(n);
+
+ if (!ifa->ifa_flags & IFA_F_SECONDARY)
+ return 0;
+
+ return print_addrinfo(who, n, arg);
+}
+
+int print_addrinfo_secondary(const struct sockaddr_nl *who, struct nlmsghdr *n,
+ void *arg)
+{
+ struct ifaddrmsg *ifa = NLMSG_DATA(n);
+
+ if (ifa->ifa_flags & IFA_F_SECONDARY)
+ return 0;
+
+ return print_addrinfo(who, n, arg);
+}
struct nlmsg_list
{
@@ -700,12 +721,32 @@ static int ipaddr_list_or_flush(int argc, char **argv, int flush)
filter.flushe = sizeof(flushb);
while (round < MAX_ROUNDS) {
+ const struct rtnl_dump_filter_arg a[3] = {
+ {
+ .filter = print_addrinfo_secondary,
+ .arg1 = stdout,
+ .junk = NULL,
+ .arg2 = NULL
+ },
+ {
+ .filter = print_addrinfo_primary,
+ .arg1 = stdout,
+ .junk = NULL,
+ .arg2 = NULL
+ },
+ {
+ .filter = NULL,
+ .arg1 = NULL,
+ .junk = NULL,
+ .arg2 = NULL
+ },
+ };
if (rtnl_wilddump_request(&rth, filter.family, RTM_GETADDR) < 0) {
perror("Cannot send dump request");
exit(1);
}
filter.flushed = 0;
- if (rtnl_dump_filter(&rth, print_addrinfo, stdout, NULL, NULL) < 0) {
+ if (rtnl_dump_filter_l(&rth, a) < 0) {
fprintf(stderr, "Flush terminated\n");
exit(1);
}