2006-07-03 01:17:05 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
2002-11-10 07:03:55 +05:30
|
|
|
/*
|
2010-08-16 23:44:46 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2002-11-10 07:03:55 +05:30
|
|
|
*
|
2010-10-29 15:16:52 +05:30
|
|
|
* Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
|
2002-11-10 07:03:55 +05:30
|
|
|
*
|
|
|
|
* Changes:
|
2010-10-29 15:16:52 +05:30
|
|
|
* Laszlo Valko <valko@linux.karinthy.hu> 990223: address label must be zero terminated
|
2002-11-10 07:03:55 +05:30
|
|
|
*/
|
|
|
|
#include <fnmatch.h>
|
2003-01-14 13:36:07 +05:30
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_arp.h>
|
2002-11-10 07:03:55 +05:30
|
|
|
|
2007-06-01 04:12:12 +05:30
|
|
|
#include "ip_common.h" /* #include "libbb.h" is inside */
|
2016-04-21 19:56:30 +05:30
|
|
|
#include "common_bufsiz.h"
|
2002-11-10 07:03:55 +05:30
|
|
|
#include "rt_names.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
2008-06-05 19:31:04 +05:30
|
|
|
#ifndef IFF_LOWER_UP
|
|
|
|
/* from linux/if.h */
|
2010-10-29 15:16:52 +05:30
|
|
|
#define IFF_LOWER_UP 0x10000 /* driver signals L1 up */
|
2008-06-05 19:31:04 +05:30
|
|
|
#endif
|
2002-11-10 07:03:55 +05:30
|
|
|
|
2020-12-29 21:23:11 +05:30
|
|
|
#ifndef IFA_F_NOPREFIXROUTE
|
|
|
|
# define IFA_FLAGS 8
|
|
|
|
/* ifa_flags */
|
|
|
|
# define IFA_F_NOPREFIXROUTE 0x200
|
|
|
|
#endif
|
|
|
|
|
2010-02-05 19:10:23 +05:30
|
|
|
struct filter_t {
|
2002-11-10 07:03:55 +05:30
|
|
|
char *label;
|
2019-05-22 17:24:46 +05:30
|
|
|
/* Flush cmd buf. If !NULL, print_addrinfo() constructs flush commands in it */
|
2003-01-14 03:10:38 +05:30
|
|
|
char *flushb;
|
2008-05-31 13:03:18 +05:30
|
|
|
struct rtnl_handle *rth;
|
|
|
|
int scope, scopemask;
|
|
|
|
int flags, flagmask;
|
2003-01-14 03:10:38 +05:30
|
|
|
int flushp;
|
|
|
|
int flushe;
|
2008-05-31 13:03:18 +05:30
|
|
|
int ifindex;
|
|
|
|
family_t family;
|
|
|
|
smallint showqueue;
|
|
|
|
smallint oneline;
|
|
|
|
smallint up;
|
2019-05-22 17:24:46 +05:30
|
|
|
/* Misnomer. Does not mean "flushed something" */
|
|
|
|
/* More like "flush commands were constructed by print_addrinfo()" */
|
2008-05-31 13:03:18 +05:30
|
|
|
smallint flushed;
|
|
|
|
inet_prefix pfx;
|
2010-02-05 19:10:23 +05:30
|
|
|
} FIX_ALIASING;
|
|
|
|
typedef struct filter_t filter_t;
|
2007-04-07 06:44:45 +05:30
|
|
|
|
2016-04-21 19:56:30 +05:30
|
|
|
#define G_filter (*(filter_t*)bb_common_bufsiz1)
|
2016-04-21 22:08:51 +05:30
|
|
|
#define INIT_G() do { setup_common_bufsiz(); } while (0)
|
2002-11-10 07:03:55 +05:30
|
|
|
|
2008-06-05 10:30:24 +05:30
|
|
|
static void print_link_flags(unsigned flags, unsigned mdown)
|
2002-11-10 07:03:55 +05:30
|
|
|
{
|
2008-06-07 20:40:29 +05:30
|
|
|
static const int flag_masks[] = {
|
|
|
|
IFF_LOOPBACK, IFF_BROADCAST, IFF_POINTOPOINT,
|
|
|
|
IFF_MULTICAST, IFF_NOARP, IFF_UP, IFF_LOWER_UP };
|
|
|
|
static const char flag_labels[] ALIGN1 =
|
|
|
|
"LOOPBACK\0""BROADCAST\0""POINTOPOINT\0"
|
|
|
|
"MULTICAST\0""NOARP\0""UP\0""LOWER_UP\0";
|
|
|
|
|
2008-06-05 12:21:06 +05:30
|
|
|
bb_putchar('<');
|
2010-05-25 13:25:42 +05:30
|
|
|
if (flags & IFF_UP && !(flags & IFF_RUNNING))
|
|
|
|
printf("NO-CARRIER,");
|
2002-11-10 07:03:55 +05:30
|
|
|
flags &= ~IFF_RUNNING;
|
|
|
|
#if 0
|
|
|
|
_PF(ALLMULTI);
|
|
|
|
_PF(PROMISC);
|
|
|
|
_PF(MASTER);
|
|
|
|
_PF(SLAVE);
|
|
|
|
_PF(DEBUG);
|
|
|
|
_PF(DYNAMIC);
|
|
|
|
_PF(AUTOMEDIA);
|
|
|
|
_PF(PORTSEL);
|
|
|
|
_PF(NOTRAILERS);
|
|
|
|
#endif
|
2008-06-07 20:40:29 +05:30
|
|
|
flags = print_flags_separated(flag_masks, flag_labels, flags, ",");
|
2006-01-25 05:38:53 +05:30
|
|
|
if (flags)
|
2008-06-05 10:30:24 +05:30
|
|
|
printf("%x", flags);
|
2002-11-10 07:03:55 +05:30
|
|
|
if (mdown)
|
2008-06-05 10:30:24 +05:30
|
|
|
printf(",M-DOWN");
|
|
|
|
printf("> ");
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
|
|
|
|
2002-12-02 07:10:05 +05:30
|
|
|
static void print_queuelen(char *name)
|
2002-11-10 07:03:55 +05:30
|
|
|
{
|
|
|
|
struct ifreq ifr;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
if (s < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset(&ifr, 0, sizeof(ifr));
|
2008-12-02 23:48:50 +05:30
|
|
|
strncpy_IFNAMSIZ(ifr.ifr_name, name);
|
2007-07-15 03:37:14 +05:30
|
|
|
if (ioctl_or_warn(s, SIOCGIFTXQLEN, &ifr) < 0) {
|
2002-11-10 07:03:55 +05:30
|
|
|
close(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
close(s);
|
|
|
|
|
|
|
|
if (ifr.ifr_qlen)
|
|
|
|
printf("qlen %d", ifr.ifr_qlen);
|
|
|
|
}
|
|
|
|
|
2009-10-08 18:05:37 +05:30
|
|
|
static NOINLINE int print_linkinfo(const struct nlmsghdr *n)
|
2002-11-10 07:03:55 +05:30
|
|
|
{
|
|
|
|
struct ifinfomsg *ifi = NLMSG_DATA(n);
|
2010-01-08 13:37:50 +05:30
|
|
|
struct rtattr *tb[IFLA_MAX+1];
|
2002-11-10 07:03:55 +05:30
|
|
|
int len = n->nlmsg_len;
|
|
|
|
|
|
|
|
if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
len -= NLMSG_LENGTH(sizeof(*ifi));
|
|
|
|
if (len < 0)
|
|
|
|
return -1;
|
|
|
|
|
2010-01-26 15:33:16 +05:30
|
|
|
if (G_filter.ifindex && ifi->ifi_index != G_filter.ifindex)
|
2002-11-10 07:03:55 +05:30
|
|
|
return 0;
|
2010-01-26 15:33:16 +05:30
|
|
|
if (G_filter.up && !(ifi->ifi_flags & IFF_UP))
|
2002-11-10 07:03:55 +05:30
|
|
|
return 0;
|
|
|
|
|
2018-02-08 13:12:37 +05:30
|
|
|
//memset(tb, 0, sizeof(tb)); - parse_rtattr does this
|
2002-11-10 07:03:55 +05:30
|
|
|
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
|
|
|
|
if (tb[IFLA_IFNAME] == NULL) {
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg("nil ifname");
|
2002-11-10 07:03:55 +05:30
|
|
|
return -1;
|
|
|
|
}
|
2010-01-26 15:33:16 +05:30
|
|
|
if (G_filter.label
|
|
|
|
&& (!G_filter.family || G_filter.family == AF_PACKET)
|
|
|
|
&& fnmatch(G_filter.label, RTA_DATA(tb[IFLA_IFNAME]), 0)
|
2007-04-07 06:44:45 +05:30
|
|
|
) {
|
2002-11-10 07:03:55 +05:30
|
|
|
return 0;
|
2007-04-07 06:44:45 +05:30
|
|
|
}
|
2002-11-10 07:03:55 +05:30
|
|
|
|
|
|
|
if (n->nlmsg_type == RTM_DELLINK)
|
2008-06-05 10:30:24 +05:30
|
|
|
printf("Deleted ");
|
2002-11-10 07:03:55 +05:30
|
|
|
|
2008-06-05 10:30:24 +05:30
|
|
|
printf("%d: %s", ifi->ifi_index,
|
2010-01-08 13:37:50 +05:30
|
|
|
/*tb[IFLA_IFNAME] ? (char*)RTA_DATA(tb[IFLA_IFNAME]) : "<nil>" - we checked tb[IFLA_IFNAME] above*/
|
|
|
|
(char*)RTA_DATA(tb[IFLA_IFNAME])
|
|
|
|
);
|
|
|
|
|
|
|
|
{
|
|
|
|
unsigned m_flag = 0;
|
|
|
|
if (tb[IFLA_LINK]) {
|
|
|
|
int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]);
|
|
|
|
if (iflink == 0)
|
|
|
|
printf("@NONE: ");
|
|
|
|
else {
|
2015-10-08 16:32:28 +05:30
|
|
|
printf("@%s: ", ll_index_to_name(iflink));
|
2010-01-08 13:37:50 +05:30
|
|
|
m_flag = ll_index_to_flags(iflink);
|
|
|
|
m_flag = !(m_flag & IFF_UP);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf(": ");
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
2010-01-08 13:37:50 +05:30
|
|
|
print_link_flags(ifi->ifi_flags, m_flag);
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if (tb[IFLA_MTU])
|
2008-06-05 10:30:24 +05:30
|
|
|
printf("mtu %u ", *(int*)RTA_DATA(tb[IFLA_MTU]));
|
2002-11-10 07:03:55 +05:30
|
|
|
if (tb[IFLA_QDISC])
|
2008-06-05 10:30:24 +05:30
|
|
|
printf("qdisc %s ", (char*)RTA_DATA(tb[IFLA_QDISC]));
|
2002-11-10 07:03:55 +05:30
|
|
|
#ifdef IFLA_MASTER
|
|
|
|
if (tb[IFLA_MASTER]) {
|
2015-10-08 16:32:28 +05:30
|
|
|
printf("master %s ", ll_index_to_name(*(int*)RTA_DATA(tb[IFLA_MASTER])));
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
|
|
|
#endif
|
2011-02-21 21:59:59 +05:30
|
|
|
/* IFLA_OPERSTATE was added to kernel with the same commit as IFF_DORMANT */
|
|
|
|
#ifdef IFF_DORMANT
|
2010-05-25 13:25:42 +05:30
|
|
|
if (tb[IFLA_OPERSTATE]) {
|
|
|
|
static const char operstate_labels[] ALIGN1 =
|
|
|
|
"UNKNOWN\0""NOTPRESENT\0""DOWN\0""LOWERLAYERDOWN\0"
|
|
|
|
"TESTING\0""DORMANT\0""UP\0";
|
|
|
|
printf("state %s ", nth_string(operstate_labels,
|
2010-05-27 17:05:04 +05:30
|
|
|
*(uint8_t *)RTA_DATA(tb[IFLA_OPERSTATE])));
|
2010-05-25 13:25:42 +05:30
|
|
|
}
|
2011-02-21 21:59:59 +05:30
|
|
|
#endif
|
2010-01-26 15:33:16 +05:30
|
|
|
if (G_filter.showqueue)
|
2002-11-10 07:03:55 +05:30
|
|
|
print_queuelen((char*)RTA_DATA(tb[IFLA_IFNAME]));
|
2004-03-15 13:59:22 +05:30
|
|
|
|
2010-01-26 15:33:16 +05:30
|
|
|
if (!G_filter.family || G_filter.family == AF_PACKET) {
|
2002-11-10 07:03:55 +05:30
|
|
|
SPRINT_BUF(b1);
|
2009-10-13 21:28:24 +05:30
|
|
|
printf("%c link/%s ", _SL_, ll_type_n2a(ifi->ifi_type, b1));
|
2002-11-10 07:03:55 +05:30
|
|
|
|
|
|
|
if (tb[IFLA_ADDRESS]) {
|
2007-09-30 21:52:36 +05:30
|
|
|
fputs(ll_addr_n2a(RTA_DATA(tb[IFLA_ADDRESS]),
|
2002-11-10 07:03:55 +05:30
|
|
|
RTA_PAYLOAD(tb[IFLA_ADDRESS]),
|
|
|
|
ifi->ifi_type,
|
2008-06-05 10:30:24 +05:30
|
|
|
b1, sizeof(b1)), stdout);
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
|
|
|
if (tb[IFLA_BROADCAST]) {
|
2007-10-30 01:03:26 +05:30
|
|
|
if (ifi->ifi_flags & IFF_POINTOPOINT)
|
2008-06-05 10:30:24 +05:30
|
|
|
printf(" peer ");
|
2002-11-10 07:03:55 +05:30
|
|
|
else
|
2008-06-05 10:30:24 +05:30
|
|
|
printf(" brd ");
|
2007-09-30 21:52:36 +05:30
|
|
|
fputs(ll_addr_n2a(RTA_DATA(tb[IFLA_BROADCAST]),
|
2002-11-10 07:03:55 +05:30
|
|
|
RTA_PAYLOAD(tb[IFLA_BROADCAST]),
|
|
|
|
ifi->ifi_type,
|
2008-06-05 10:30:24 +05:30
|
|
|
b1, sizeof(b1)), stdout);
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
|
|
|
}
|
2008-06-05 10:30:24 +05:30
|
|
|
bb_putchar('\n');
|
2009-11-02 18:49:51 +05:30
|
|
|
/*fflush_all();*/
|
2002-11-10 07:03:55 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-01-14 03:10:38 +05:30
|
|
|
static int flush_update(void)
|
|
|
|
{
|
2019-05-22 17:24:46 +05:30
|
|
|
if (rtnl_send_check(G_filter.rth, G_filter.flushb, G_filter.flushp) < 0) {
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_perror_msg("can't send flush request");
|
2003-01-14 03:10:38 +05:30
|
|
|
return -1;
|
|
|
|
}
|
2010-01-26 15:33:16 +05:30
|
|
|
G_filter.flushp = 0;
|
2003-01-14 03:10:38 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-05 15:36:05 +05:30
|
|
|
static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM,
|
2008-07-05 14:48:54 +05:30
|
|
|
struct nlmsghdr *n, void *arg UNUSED_PARAM)
|
2002-11-10 07:03:55 +05:30
|
|
|
{
|
|
|
|
struct ifaddrmsg *ifa = NLMSG_DATA(n);
|
|
|
|
int len = n->nlmsg_len;
|
2020-06-29 21:27:25 +05:30
|
|
|
unsigned int ifa_flags;
|
2015-10-14 17:26:42 +05:30
|
|
|
struct rtattr *rta_tb[IFA_MAX+1];
|
2002-11-10 07:03:55 +05:30
|
|
|
|
|
|
|
if (n->nlmsg_type != RTM_NEWADDR && n->nlmsg_type != RTM_DELADDR)
|
|
|
|
return 0;
|
|
|
|
len -= NLMSG_LENGTH(sizeof(*ifa));
|
|
|
|
if (len < 0) {
|
2003-03-19 14:43:01 +05:30
|
|
|
bb_error_msg("wrong nlmsg len %d", len);
|
2002-11-10 07:03:55 +05:30
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-01-26 15:33:16 +05:30
|
|
|
if (G_filter.flushb && n->nlmsg_type != RTM_NEWADDR)
|
2003-01-14 03:10:38 +05:30
|
|
|
return 0;
|
|
|
|
|
2018-02-08 13:12:37 +05:30
|
|
|
//memset(rta_tb, 0, sizeof(rta_tb)); - parse_rtattr does this
|
2002-11-10 07:03:55 +05:30
|
|
|
parse_rtattr(rta_tb, IFA_MAX, IFA_RTA(ifa), n->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa)));
|
|
|
|
|
2020-06-29 21:27:25 +05:30
|
|
|
ifa_flags = rta_tb[IFA_FLAGS] ? *(__u32*)RTA_DATA(rta_tb[IFA_FLAGS]) : ifa->ifa_flags;
|
|
|
|
|
2002-11-10 07:03:55 +05:30
|
|
|
if (!rta_tb[IFA_LOCAL])
|
|
|
|
rta_tb[IFA_LOCAL] = rta_tb[IFA_ADDRESS];
|
|
|
|
if (!rta_tb[IFA_ADDRESS])
|
|
|
|
rta_tb[IFA_ADDRESS] = rta_tb[IFA_LOCAL];
|
|
|
|
|
2010-01-26 15:33:16 +05:30
|
|
|
if (G_filter.ifindex && G_filter.ifindex != ifa->ifa_index)
|
2002-11-10 07:03:55 +05:30
|
|
|
return 0;
|
2010-01-26 15:33:16 +05:30
|
|
|
if ((G_filter.scope ^ ifa->ifa_scope) & G_filter.scopemask)
|
2002-11-10 07:03:55 +05:30
|
|
|
return 0;
|
2020-06-29 21:27:25 +05:30
|
|
|
if ((G_filter.flags ^ ifa_flags) & G_filter.flagmask)
|
2002-11-10 07:03:55 +05:30
|
|
|
return 0;
|
2010-01-26 15:33:16 +05:30
|
|
|
if (G_filter.label) {
|
2002-11-10 07:03:55 +05:30
|
|
|
const char *label;
|
|
|
|
if (rta_tb[IFA_LABEL])
|
|
|
|
label = RTA_DATA(rta_tb[IFA_LABEL]);
|
|
|
|
else
|
2015-10-08 16:32:28 +05:30
|
|
|
label = ll_index_to_name(ifa->ifa_index);
|
2010-01-26 15:33:16 +05:30
|
|
|
if (fnmatch(G_filter.label, label, 0) != 0)
|
2002-11-10 07:03:55 +05:30
|
|
|
return 0;
|
|
|
|
}
|
2010-01-26 15:33:16 +05:30
|
|
|
if (G_filter.pfx.family) {
|
2002-11-10 07:03:55 +05:30
|
|
|
if (rta_tb[IFA_LOCAL]) {
|
|
|
|
inet_prefix dst;
|
|
|
|
memset(&dst, 0, sizeof(dst));
|
|
|
|
dst.family = ifa->ifa_family;
|
|
|
|
memcpy(&dst.data, RTA_DATA(rta_tb[IFA_LOCAL]), RTA_PAYLOAD(rta_tb[IFA_LOCAL]));
|
2010-01-26 15:33:16 +05:30
|
|
|
if (inet_addr_match(&dst, &G_filter.pfx, G_filter.pfx.bitlen))
|
2002-11-10 07:03:55 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-26 15:33:16 +05:30
|
|
|
if (G_filter.flushb) {
|
2003-01-14 03:10:38 +05:30
|
|
|
struct nlmsghdr *fn;
|
2010-01-26 15:33:16 +05:30
|
|
|
if (NLMSG_ALIGN(G_filter.flushp) + n->nlmsg_len > G_filter.flushe) {
|
2003-01-14 03:10:38 +05:30
|
|
|
if (flush_update())
|
|
|
|
return -1;
|
|
|
|
}
|
2010-01-26 15:33:16 +05:30
|
|
|
fn = (struct nlmsghdr*)(G_filter.flushb + NLMSG_ALIGN(G_filter.flushp));
|
2003-01-14 03:10:38 +05:30
|
|
|
memcpy(fn, n, n->nlmsg_len);
|
|
|
|
fn->nlmsg_type = RTM_DELADDR;
|
|
|
|
fn->nlmsg_flags = NLM_F_REQUEST;
|
2010-01-26 15:33:16 +05:30
|
|
|
fn->nlmsg_seq = ++G_filter.rth->seq;
|
|
|
|
G_filter.flushp = (((char*)fn) + n->nlmsg_len) - G_filter.flushb;
|
|
|
|
G_filter.flushed = 1;
|
2003-01-14 03:10:38 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-11-10 07:03:55 +05:30
|
|
|
if (n->nlmsg_type == RTM_DELADDR)
|
2008-06-05 10:30:24 +05:30
|
|
|
printf("Deleted ");
|
2002-11-10 07:03:55 +05:30
|
|
|
|
2010-01-26 15:33:16 +05:30
|
|
|
if (G_filter.oneline)
|
2008-06-05 10:30:24 +05:30
|
|
|
printf("%u: %s", ifa->ifa_index, ll_index_to_name(ifa->ifa_index));
|
2002-11-10 07:03:55 +05:30
|
|
|
if (ifa->ifa_family == AF_INET)
|
2008-06-05 10:30:24 +05:30
|
|
|
printf(" inet ");
|
2002-11-10 07:03:55 +05:30
|
|
|
else if (ifa->ifa_family == AF_INET6)
|
2008-06-05 10:30:24 +05:30
|
|
|
printf(" inet6 ");
|
2002-11-10 07:03:55 +05:30
|
|
|
else
|
2008-06-05 10:30:24 +05:30
|
|
|
printf(" family %d ", ifa->ifa_family);
|
2002-11-10 07:03:55 +05:30
|
|
|
|
|
|
|
if (rta_tb[IFA_LOCAL]) {
|
2015-10-14 17:26:42 +05:30
|
|
|
fputs(rt_addr_n2a(ifa->ifa_family, RTA_DATA(rta_tb[IFA_LOCAL])),
|
|
|
|
stdout
|
|
|
|
);
|
2002-11-10 07:03:55 +05:30
|
|
|
|
2009-03-05 14:51:57 +05:30
|
|
|
if (rta_tb[IFA_ADDRESS] == NULL
|
|
|
|
|| memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]), 4) == 0
|
|
|
|
) {
|
2008-06-05 10:30:24 +05:30
|
|
|
printf("/%d ", ifa->ifa_prefixlen);
|
2002-11-10 07:03:55 +05:30
|
|
|
} else {
|
2008-06-05 10:30:24 +05:30
|
|
|
printf(" peer %s/%d ",
|
2015-10-14 17:26:42 +05:30
|
|
|
rt_addr_n2a(ifa->ifa_family, RTA_DATA(rta_tb[IFA_ADDRESS])),
|
|
|
|
ifa->ifa_prefixlen
|
|
|
|
);
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rta_tb[IFA_BROADCAST]) {
|
2008-06-05 10:30:24 +05:30
|
|
|
printf("brd %s ",
|
2002-11-10 07:03:55 +05:30
|
|
|
rt_addr_n2a(ifa->ifa_family,
|
2015-10-14 17:26:42 +05:30
|
|
|
RTA_DATA(rta_tb[IFA_BROADCAST]))
|
2013-01-14 20:27:44 +05:30
|
|
|
);
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
|
|
|
if (rta_tb[IFA_ANYCAST]) {
|
2008-06-05 10:30:24 +05:30
|
|
|
printf("any %s ",
|
2002-11-10 07:03:55 +05:30
|
|
|
rt_addr_n2a(ifa->ifa_family,
|
2015-10-14 17:26:42 +05:30
|
|
|
RTA_DATA(rta_tb[IFA_ANYCAST]))
|
2013-01-14 20:27:44 +05:30
|
|
|
);
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
2015-10-08 16:32:28 +05:30
|
|
|
printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope));
|
2020-06-29 21:27:25 +05:30
|
|
|
if (ifa_flags & IFA_F_SECONDARY) {
|
|
|
|
ifa_flags &= ~IFA_F_SECONDARY;
|
2008-06-05 10:30:24 +05:30
|
|
|
printf("secondary ");
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
2020-06-29 21:27:25 +05:30
|
|
|
if (ifa_flags & IFA_F_TENTATIVE) {
|
|
|
|
ifa_flags &= ~IFA_F_TENTATIVE;
|
2008-06-05 10:30:24 +05:30
|
|
|
printf("tentative ");
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
2020-06-29 21:27:25 +05:30
|
|
|
if (ifa_flags & IFA_F_DADFAILED) {
|
|
|
|
ifa_flags &= ~IFA_F_DADFAILED;
|
2018-12-31 23:22:32 +05:30
|
|
|
printf("dadfailed ");
|
|
|
|
}
|
2020-06-29 21:27:25 +05:30
|
|
|
if (ifa_flags & IFA_F_DEPRECATED) {
|
|
|
|
ifa_flags &= ~IFA_F_DEPRECATED;
|
2008-06-05 10:30:24 +05:30
|
|
|
printf("deprecated ");
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
2020-06-29 21:27:25 +05:30
|
|
|
if (!(ifa_flags & IFA_F_PERMANENT)) {
|
2008-06-05 10:30:24 +05:30
|
|
|
printf("dynamic ");
|
2002-11-10 07:03:55 +05:30
|
|
|
} else
|
2020-06-29 21:27:25 +05:30
|
|
|
ifa_flags &= ~IFA_F_PERMANENT;
|
|
|
|
if (ifa_flags & IFA_F_NOPREFIXROUTE) {
|
|
|
|
ifa_flags &= ~IFA_F_NOPREFIXROUTE;
|
|
|
|
printf("noprefixroute ");
|
|
|
|
}
|
|
|
|
if (ifa_flags)
|
|
|
|
printf("flags %02x ", ifa_flags);
|
2002-11-10 07:03:55 +05:30
|
|
|
if (rta_tb[IFA_LABEL])
|
2008-06-05 10:30:24 +05:30
|
|
|
fputs((char*)RTA_DATA(rta_tb[IFA_LABEL]), stdout);
|
2002-11-10 07:03:55 +05:30
|
|
|
if (rta_tb[IFA_CACHEINFO]) {
|
|
|
|
struct ifa_cacheinfo *ci = RTA_DATA(rta_tb[IFA_CACHEINFO]);
|
|
|
|
char buf[128];
|
2008-06-05 10:30:24 +05:30
|
|
|
bb_putchar(_SL_);
|
2002-11-10 07:03:55 +05:30
|
|
|
if (ci->ifa_valid == 0xFFFFFFFFU)
|
|
|
|
sprintf(buf, "valid_lft forever");
|
|
|
|
else
|
|
|
|
sprintf(buf, "valid_lft %dsec", ci->ifa_valid);
|
|
|
|
if (ci->ifa_prefered == 0xFFFFFFFFU)
|
|
|
|
sprintf(buf+strlen(buf), " preferred_lft forever");
|
|
|
|
else
|
|
|
|
sprintf(buf+strlen(buf), " preferred_lft %dsec", ci->ifa_prefered);
|
2008-06-05 10:30:24 +05:30
|
|
|
printf(" %s", buf);
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
2008-06-05 10:30:24 +05:30
|
|
|
bb_putchar('\n');
|
2009-11-02 18:49:51 +05:30
|
|
|
/*fflush_all();*/
|
2002-11-10 07:03:55 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-05 15:36:05 +05:30
|
|
|
struct nlmsg_list {
|
2002-11-10 07:03:55 +05:30
|
|
|
struct nlmsg_list *next;
|
2010-10-29 15:16:52 +05:30
|
|
|
struct nlmsghdr h;
|
2002-11-10 07:03:55 +05:30
|
|
|
};
|
|
|
|
|
2008-06-05 10:30:24 +05:30
|
|
|
static int print_selected_addrinfo(int ifindex, struct nlmsg_list *ainfo)
|
2002-11-10 07:03:55 +05:30
|
|
|
{
|
2007-04-07 06:44:45 +05:30
|
|
|
for (; ainfo; ainfo = ainfo->next) {
|
2002-11-10 07:03:55 +05:30
|
|
|
struct nlmsghdr *n = &ainfo->h;
|
|
|
|
struct ifaddrmsg *ifa = NLMSG_DATA(n);
|
|
|
|
|
|
|
|
if (n->nlmsg_type != RTM_NEWADDR)
|
|
|
|
continue;
|
|
|
|
if (n->nlmsg_len < NLMSG_LENGTH(sizeof(ifa)))
|
|
|
|
return -1;
|
2010-01-26 15:33:16 +05:30
|
|
|
if (ifa->ifa_index != ifindex
|
|
|
|
|| (G_filter.family && G_filter.family != ifa->ifa_family)
|
|
|
|
) {
|
2002-11-10 07:03:55 +05:30
|
|
|
continue;
|
2010-01-26 15:33:16 +05:30
|
|
|
}
|
2008-06-05 10:30:24 +05:30
|
|
|
print_addrinfo(NULL, n, NULL);
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-05 15:36:05 +05:30
|
|
|
static int FAST_FUNC store_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
2002-11-10 07:03:55 +05:30
|
|
|
{
|
|
|
|
struct nlmsg_list **linfo = (struct nlmsg_list**)arg;
|
|
|
|
struct nlmsg_list *h;
|
|
|
|
struct nlmsg_list **lp;
|
|
|
|
|
2010-01-08 13:37:50 +05:30
|
|
|
h = xzalloc(n->nlmsg_len + sizeof(void*));
|
2002-11-10 07:03:55 +05:30
|
|
|
|
|
|
|
memcpy(&h->h, n, n->nlmsg_len);
|
2010-01-08 13:37:50 +05:30
|
|
|
/*h->next = NULL; - xzalloc did it */
|
2002-11-10 07:03:55 +05:30
|
|
|
|
2008-05-31 13:03:18 +05:30
|
|
|
for (lp = linfo; *lp; lp = &(*lp)->next)
|
|
|
|
continue;
|
2002-11-10 07:03:55 +05:30
|
|
|
*lp = h;
|
|
|
|
|
|
|
|
ll_remember_index(who, n, NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-12-02 07:10:05 +05:30
|
|
|
static void ipaddr_reset_filter(int _oneline)
|
2002-11-10 07:03:55 +05:30
|
|
|
{
|
2010-01-26 15:33:16 +05:30
|
|
|
memset(&G_filter, 0, sizeof(G_filter));
|
|
|
|
G_filter.oneline = _oneline;
|
2002-12-02 07:10:05 +05:30
|
|
|
}
|
|
|
|
|
2007-04-07 06:44:45 +05:30
|
|
|
/* Return value becomes exitcode. It's okay to not return at all */
|
2010-07-25 02:57:38 +05:30
|
|
|
int FAST_FUNC ipaddr_list_or_flush(char **argv, int flush)
|
2002-12-02 07:10:05 +05:30
|
|
|
{
|
2007-08-13 02:28:27 +05:30
|
|
|
static const char option[] ALIGN1 = "to\0""scope\0""up\0""label\0""dev\0";
|
2006-02-22 22:31:00 +05:30
|
|
|
|
2002-11-10 07:03:55 +05:30
|
|
|
struct nlmsg_list *linfo = NULL;
|
|
|
|
struct nlmsg_list *ainfo = NULL;
|
|
|
|
struct nlmsg_list *l;
|
|
|
|
struct rtnl_handle rth;
|
|
|
|
char *filter_dev = NULL;
|
|
|
|
|
|
|
|
ipaddr_reset_filter(oneline);
|
2010-01-26 15:33:16 +05:30
|
|
|
G_filter.showqueue = 1;
|
2002-11-10 07:03:55 +05:30
|
|
|
|
2010-01-26 15:33:16 +05:30
|
|
|
if (G_filter.family == AF_UNSPEC)
|
|
|
|
G_filter.family = preferred_family;
|
2002-11-10 07:03:55 +05:30
|
|
|
|
2003-01-14 03:10:38 +05:30
|
|
|
if (flush) {
|
2007-11-19 04:26:25 +05:30
|
|
|
if (!*argv) {
|
2007-04-07 06:44:45 +05:30
|
|
|
bb_error_msg_and_die(bb_msg_requires_arg, "flush");
|
2003-01-14 03:10:38 +05:30
|
|
|
}
|
2010-01-26 15:33:16 +05:30
|
|
|
if (G_filter.family == AF_PACKET) {
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("can't flush link addresses");
|
2003-01-14 03:10:38 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-19 04:26:25 +05:30
|
|
|
while (*argv) {
|
2010-05-25 22:16:09 +05:30
|
|
|
const smalluint key = index_in_strings(option, *argv);
|
|
|
|
if (key == 0) { /* to */
|
2010-07-04 07:25:43 +05:30
|
|
|
NEXT_ARG();
|
|
|
|
get_prefix(&G_filter.pfx, *argv, G_filter.family);
|
|
|
|
if (G_filter.family == AF_UNSPEC) {
|
|
|
|
G_filter.family = G_filter.pfx.family;
|
|
|
|
}
|
2010-05-25 22:16:09 +05:30
|
|
|
} else if (key == 1) { /* scope */
|
2010-07-04 07:25:43 +05:30
|
|
|
uint32_t scope = 0;
|
|
|
|
NEXT_ARG();
|
|
|
|
G_filter.scopemask = -1;
|
|
|
|
if (rtnl_rtscope_a2n(&scope, *argv)) {
|
|
|
|
if (strcmp(*argv, "all") != 0) {
|
2015-10-14 16:51:01 +05:30
|
|
|
invarg_1_to_2(*argv, "scope");
|
2002-12-02 07:10:05 +05:30
|
|
|
}
|
2010-07-04 07:25:43 +05:30
|
|
|
scope = RT_SCOPE_NOWHERE;
|
|
|
|
G_filter.scopemask = 0;
|
|
|
|
}
|
|
|
|
G_filter.scope = scope;
|
2010-05-25 22:16:09 +05:30
|
|
|
} else if (key == 2) { /* up */
|
2010-07-04 07:25:43 +05:30
|
|
|
G_filter.up = 1;
|
2010-05-25 22:16:09 +05:30
|
|
|
} else if (key == 3) { /* label */
|
2010-07-04 07:25:43 +05:30
|
|
|
NEXT_ARG();
|
|
|
|
G_filter.label = *argv;
|
2010-05-25 22:16:09 +05:30
|
|
|
} else {
|
|
|
|
if (key == 4) /* dev */
|
2002-12-02 07:10:05 +05:30
|
|
|
NEXT_ARG();
|
2010-05-25 22:16:09 +05:30
|
|
|
if (filter_dev)
|
|
|
|
duparg2("dev", *argv);
|
|
|
|
filter_dev = *argv;
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
2002-12-02 07:10:05 +05:30
|
|
|
argv++;
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
|
|
|
|
2007-04-12 17:04:39 +05:30
|
|
|
xrtnl_open(&rth);
|
2002-11-10 07:03:55 +05:30
|
|
|
|
2007-04-12 17:04:39 +05:30
|
|
|
xrtnl_wilddump_request(&rth, preferred_family, RTM_GETLINK);
|
|
|
|
xrtnl_dump_filter(&rth, store_nlmsg, &linfo);
|
2002-11-10 07:03:55 +05:30
|
|
|
|
|
|
|
if (filter_dev) {
|
2010-01-26 15:33:16 +05:30
|
|
|
G_filter.ifindex = xll_name_to_index(filter_dev);
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
|
|
|
|
2003-01-14 03:10:38 +05:30
|
|
|
if (flush) {
|
|
|
|
char flushb[4096-512];
|
|
|
|
|
2010-01-26 15:33:16 +05:30
|
|
|
G_filter.flushb = flushb;
|
|
|
|
G_filter.flushp = 0;
|
|
|
|
G_filter.flushe = sizeof(flushb);
|
|
|
|
G_filter.rth = &rth;
|
2003-01-14 03:10:38 +05:30
|
|
|
|
|
|
|
for (;;) {
|
2010-01-26 15:33:16 +05:30
|
|
|
xrtnl_wilddump_request(&rth, G_filter.family, RTM_GETADDR);
|
|
|
|
G_filter.flushed = 0;
|
2008-06-05 10:30:24 +05:30
|
|
|
xrtnl_dump_filter(&rth, print_addrinfo, NULL);
|
2010-01-26 15:33:16 +05:30
|
|
|
if (G_filter.flushed == 0) {
|
2003-01-14 03:10:38 +05:30
|
|
|
return 0;
|
|
|
|
}
|
2010-01-26 15:33:16 +05:30
|
|
|
if (flush_update() < 0) {
|
2007-04-07 06:44:45 +05:30
|
|
|
return 1;
|
2010-01-26 15:33:16 +05:30
|
|
|
}
|
2003-01-14 03:10:38 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-26 15:33:16 +05:30
|
|
|
if (G_filter.family != AF_PACKET) {
|
|
|
|
xrtnl_wilddump_request(&rth, G_filter.family, RTM_GETADDR);
|
2007-04-12 17:04:39 +05:30
|
|
|
xrtnl_dump_filter(&rth, store_nlmsg, &ainfo);
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
|
|
|
|
2010-01-26 15:33:16 +05:30
|
|
|
if (G_filter.family && G_filter.family != AF_PACKET) {
|
2002-11-10 07:03:55 +05:30
|
|
|
struct nlmsg_list **lp;
|
2007-11-19 04:26:25 +05:30
|
|
|
lp = &linfo;
|
2002-11-10 07:03:55 +05:30
|
|
|
|
2007-11-19 04:26:25 +05:30
|
|
|
while ((l = *lp) != NULL) {
|
2002-11-10 07:03:55 +05:30
|
|
|
int ok = 0;
|
|
|
|
struct ifinfomsg *ifi = NLMSG_DATA(&l->h);
|
|
|
|
struct nlmsg_list *a;
|
|
|
|
|
2007-11-19 04:26:25 +05:30
|
|
|
for (a = ainfo; a; a = a->next) {
|
2002-11-10 07:03:55 +05:30
|
|
|
struct nlmsghdr *n = &a->h;
|
|
|
|
struct ifaddrmsg *ifa = NLMSG_DATA(n);
|
|
|
|
|
2010-01-26 15:33:16 +05:30
|
|
|
if (ifa->ifa_index != ifi->ifi_index
|
|
|
|
|| (G_filter.family && G_filter.family != ifa->ifa_family)
|
|
|
|
) {
|
2002-11-10 07:03:55 +05:30
|
|
|
continue;
|
2010-01-26 15:33:16 +05:30
|
|
|
}
|
|
|
|
if ((G_filter.scope ^ ifa->ifa_scope) & G_filter.scopemask)
|
2002-11-10 07:03:55 +05:30
|
|
|
continue;
|
2010-01-26 15:33:16 +05:30
|
|
|
if ((G_filter.flags ^ ifa->ifa_flags) & G_filter.flagmask)
|
2002-11-10 07:03:55 +05:30
|
|
|
continue;
|
2010-01-26 15:33:16 +05:30
|
|
|
if (G_filter.pfx.family || G_filter.label) {
|
2002-11-10 07:03:55 +05:30
|
|
|
struct rtattr *tb[IFA_MAX+1];
|
2018-02-08 13:12:37 +05:30
|
|
|
//memset(tb, 0, sizeof(tb)); - parse_rtattr does this
|
2002-11-10 07:03:55 +05:30
|
|
|
parse_rtattr(tb, IFA_MAX, IFA_RTA(ifa), IFA_PAYLOAD(n));
|
|
|
|
if (!tb[IFA_LOCAL])
|
|
|
|
tb[IFA_LOCAL] = tb[IFA_ADDRESS];
|
|
|
|
|
2010-01-26 15:33:16 +05:30
|
|
|
if (G_filter.pfx.family && tb[IFA_LOCAL]) {
|
2002-11-10 07:03:55 +05:30
|
|
|
inet_prefix dst;
|
|
|
|
memset(&dst, 0, sizeof(dst));
|
|
|
|
dst.family = ifa->ifa_family;
|
|
|
|
memcpy(&dst.data, RTA_DATA(tb[IFA_LOCAL]), RTA_PAYLOAD(tb[IFA_LOCAL]));
|
2010-01-26 15:33:16 +05:30
|
|
|
if (inet_addr_match(&dst, &G_filter.pfx, G_filter.pfx.bitlen))
|
2002-11-10 07:03:55 +05:30
|
|
|
continue;
|
|
|
|
}
|
2010-01-26 15:33:16 +05:30
|
|
|
if (G_filter.label) {
|
2002-11-10 07:03:55 +05:30
|
|
|
const char *label;
|
|
|
|
if (tb[IFA_LABEL])
|
|
|
|
label = RTA_DATA(tb[IFA_LABEL]);
|
|
|
|
else
|
2015-10-08 16:32:28 +05:30
|
|
|
label = ll_index_to_name(ifa->ifa_index);
|
2010-01-26 15:33:16 +05:30
|
|
|
if (fnmatch(G_filter.label, label, 0) != 0)
|
2002-11-10 07:03:55 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ok = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ok)
|
|
|
|
*lp = l->next;
|
|
|
|
else
|
|
|
|
lp = &l->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-07 06:44:45 +05:30
|
|
|
for (l = linfo; l; l = l->next) {
|
2019-03-30 22:54:46 +05:30
|
|
|
if ((oneline && G_filter.family != AF_PACKET)
|
2018-03-08 20:25:07 +05:30
|
|
|
/* ^^^^^^^^^ "ip -oneline a" does not print link info */
|
2019-04-29 04:04:07 +05:30
|
|
|
|| (print_linkinfo(&l->h) == 0)
|
2018-03-08 20:25:07 +05:30
|
|
|
) {
|
2002-11-10 07:03:55 +05:30
|
|
|
struct ifinfomsg *ifi = NLMSG_DATA(&l->h);
|
2010-01-26 15:33:16 +05:30
|
|
|
if (G_filter.family != AF_PACKET)
|
2008-06-05 10:30:24 +05:30
|
|
|
print_selected_addrinfo(ifi->ifi_index, ainfo);
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-07 06:44:45 +05:30
|
|
|
return 0;
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
|
|
|
|
2020-06-29 21:27:26 +05:30
|
|
|
static void set_lifetime(unsigned int *lifetime, char *argv, const char *errmsg)
|
|
|
|
{
|
|
|
|
if (strcmp(argv, "forever") == 0)
|
|
|
|
*lifetime = INFINITY_LIFE_TIME;
|
|
|
|
else
|
|
|
|
*lifetime = get_u32(argv, errmsg);
|
|
|
|
}
|
|
|
|
|
2002-12-02 07:10:05 +05:30
|
|
|
static int default_scope(inet_prefix *lcl)
|
2002-11-10 07:03:55 +05:30
|
|
|
{
|
|
|
|
if (lcl->family == AF_INET) {
|
2007-01-01 00:27:37 +05:30
|
|
|
if (lcl->bytelen >= 1 && *(uint8_t*)&lcl->data == 127)
|
2002-11-10 07:03:55 +05:30
|
|
|
return RT_SCOPE_HOST;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-07 06:44:45 +05:30
|
|
|
/* Return value becomes exitcode. It's okay to not return at all */
|
2015-05-20 18:57:44 +05:30
|
|
|
static int ipaddr_modify(int cmd, int flags, char **argv)
|
2002-11-10 07:03:55 +05:30
|
|
|
{
|
2017-04-07 21:44:46 +05:30
|
|
|
/* If you add stuff here, update ipaddr_full_usage */
|
2007-08-13 02:28:27 +05:30
|
|
|
static const char option[] ALIGN1 =
|
2007-07-24 21:24:42 +05:30
|
|
|
"peer\0""remote\0""broadcast\0""brd\0"
|
2020-06-29 21:27:26 +05:30
|
|
|
"anycast\0""valid_lft\0""preferred_lft\0"
|
|
|
|
"scope\0""dev\0""label\0""noprefixroute\0""local\0";
|
2017-04-07 21:44:46 +05:30
|
|
|
#define option_peer option
|
|
|
|
#define option_broadcast (option + sizeof("peer") + sizeof("remote"))
|
|
|
|
#define option_anycast (option_broadcast + sizeof("broadcast") + sizeof("brd"))
|
2020-06-29 21:27:26 +05:30
|
|
|
#define option_valid_lft (option_anycast + sizeof("anycast"))
|
|
|
|
#define option_pref_lft (option_valid_lft + sizeof("valid_lft"))
|
2002-11-10 07:03:55 +05:30
|
|
|
struct rtnl_handle rth;
|
|
|
|
struct {
|
2007-07-24 21:24:42 +05:30
|
|
|
struct nlmsghdr n;
|
|
|
|
struct ifaddrmsg ifa;
|
|
|
|
char buf[256];
|
2002-11-10 07:03:55 +05:30
|
|
|
} req;
|
2007-07-24 21:24:42 +05:30
|
|
|
char *d = NULL;
|
|
|
|
char *l = NULL;
|
2020-06-29 21:27:26 +05:30
|
|
|
char *valid_lftp = NULL;
|
|
|
|
char *preferred_lftp = NULL;
|
2002-11-10 07:03:55 +05:30
|
|
|
inet_prefix lcl;
|
|
|
|
inet_prefix peer;
|
|
|
|
int local_len = 0;
|
|
|
|
int peer_len = 0;
|
|
|
|
int brd_len = 0;
|
|
|
|
int any_len = 0;
|
2007-06-20 20:23:49 +05:30
|
|
|
bool scoped = 0;
|
2020-06-29 21:27:26 +05:30
|
|
|
__u32 valid_lft = INFINITY_LIFE_TIME;
|
|
|
|
__u32 preferred_lft = INFINITY_LIFE_TIME;
|
2020-06-29 21:27:25 +05:30
|
|
|
unsigned int ifa_flags = 0;
|
2002-11-10 07:03:55 +05:30
|
|
|
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
|
|
|
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
|
2015-05-20 18:57:44 +05:30
|
|
|
req.n.nlmsg_flags = NLM_F_REQUEST | flags;
|
2002-11-10 07:03:55 +05:30
|
|
|
req.n.nlmsg_type = cmd;
|
|
|
|
req.ifa.ifa_family = preferred_family;
|
|
|
|
|
2007-11-19 04:26:25 +05:30
|
|
|
while (*argv) {
|
2013-07-15 08:45:46 +05:30
|
|
|
unsigned arg = index_in_strings(option, *argv);
|
|
|
|
/* if search fails, "local" is assumed */
|
2002-12-02 07:10:05 +05:30
|
|
|
|
2013-07-15 08:45:46 +05:30
|
|
|
if (arg <= 1) { /* peer, remote */
|
2020-06-29 21:27:26 +05:30
|
|
|
NEXT_ARG();
|
2010-05-25 22:16:09 +05:30
|
|
|
if (peer_len) {
|
2017-04-07 21:44:46 +05:30
|
|
|
duparg(option_peer, *argv);
|
2002-12-02 07:10:05 +05:30
|
|
|
}
|
2010-05-25 22:16:09 +05:30
|
|
|
get_prefix(&peer, *argv, req.ifa.ifa_family);
|
|
|
|
peer_len = peer.bytelen;
|
|
|
|
if (req.ifa.ifa_family == AF_UNSPEC) {
|
|
|
|
req.ifa.ifa_family = peer.family;
|
|
|
|
}
|
|
|
|
addattr_l(&req.n, sizeof(req), IFA_ADDRESS, &peer.data, peer.bytelen);
|
|
|
|
req.ifa.ifa_prefixlen = peer.bitlen;
|
|
|
|
} else if (arg <= 3) { /* broadcast, brd */
|
|
|
|
inet_prefix addr;
|
2020-06-29 21:27:26 +05:30
|
|
|
NEXT_ARG();
|
2010-05-25 22:16:09 +05:30
|
|
|
if (brd_len) {
|
2017-04-07 21:44:46 +05:30
|
|
|
duparg(option_broadcast, *argv);
|
2010-05-25 22:16:09 +05:30
|
|
|
}
|
|
|
|
if (LONE_CHAR(*argv, '+')) {
|
|
|
|
brd_len = -1;
|
|
|
|
} else if (LONE_DASH(*argv)) {
|
|
|
|
brd_len = -2;
|
|
|
|
} else {
|
2002-11-10 07:03:55 +05:30
|
|
|
get_addr(&addr, *argv, req.ifa.ifa_family);
|
2010-05-25 22:16:09 +05:30
|
|
|
if (req.ifa.ifa_family == AF_UNSPEC)
|
2002-11-10 07:03:55 +05:30
|
|
|
req.ifa.ifa_family = addr.family;
|
2010-05-25 22:16:09 +05:30
|
|
|
addattr_l(&req.n, sizeof(req), IFA_BROADCAST, &addr.data, addr.bytelen);
|
|
|
|
brd_len = addr.bytelen;
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
2010-05-25 22:16:09 +05:30
|
|
|
} else if (arg == 4) { /* anycast */
|
|
|
|
inet_prefix addr;
|
2020-06-29 21:27:26 +05:30
|
|
|
NEXT_ARG();
|
2010-05-25 22:16:09 +05:30
|
|
|
if (any_len) {
|
2017-04-07 21:44:46 +05:30
|
|
|
duparg(option_anycast, *argv);
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
2010-05-25 22:16:09 +05:30
|
|
|
get_addr(&addr, *argv, req.ifa.ifa_family);
|
|
|
|
if (req.ifa.ifa_family == AF_UNSPEC) {
|
|
|
|
req.ifa.ifa_family = addr.family;
|
|
|
|
}
|
|
|
|
addattr_l(&req.n, sizeof(req), IFA_ANYCAST, &addr.data, addr.bytelen);
|
|
|
|
any_len = addr.bytelen;
|
2020-06-29 21:27:26 +05:30
|
|
|
} else if (arg == 5) { /* valid_lft */
|
|
|
|
if (valid_lftp)
|
|
|
|
duparg(option_valid_lft, *argv);
|
|
|
|
NEXT_ARG();
|
|
|
|
valid_lftp = *argv;
|
|
|
|
set_lifetime(&valid_lft, *argv, option_valid_lft);
|
|
|
|
} else if (arg == 6) { /* preferred_lft */
|
|
|
|
if (preferred_lftp)
|
|
|
|
duparg(option_pref_lft, *argv);
|
|
|
|
NEXT_ARG();
|
|
|
|
preferred_lftp = *argv;
|
|
|
|
set_lifetime(&preferred_lft, *argv, option_pref_lft);
|
|
|
|
} else if (arg == 7) { /* scope */
|
2010-05-25 22:16:09 +05:30
|
|
|
uint32_t scope = 0;
|
2020-06-29 21:27:26 +05:30
|
|
|
NEXT_ARG();
|
2010-05-25 22:16:09 +05:30
|
|
|
if (rtnl_rtscope_a2n(&scope, *argv)) {
|
2015-10-14 16:51:01 +05:30
|
|
|
invarg_1_to_2(*argv, "scope");
|
2010-05-25 22:16:09 +05:30
|
|
|
}
|
|
|
|
req.ifa.ifa_scope = scope;
|
|
|
|
scoped = 1;
|
2020-06-29 21:27:26 +05:30
|
|
|
} else if (arg == 8) { /* dev */
|
|
|
|
NEXT_ARG();
|
2010-05-25 22:16:09 +05:30
|
|
|
d = *argv;
|
2020-06-29 21:27:26 +05:30
|
|
|
} else if (arg == 9) { /* label */
|
|
|
|
NEXT_ARG();
|
2010-05-25 22:16:09 +05:30
|
|
|
l = *argv;
|
2010-07-04 07:25:43 +05:30
|
|
|
addattr_l(&req.n, sizeof(req), IFA_LABEL, l, strlen(l) + 1);
|
2020-06-29 21:27:26 +05:30
|
|
|
} else if (arg == 10) { /* noprefixroute */
|
2020-06-29 21:27:25 +05:30
|
|
|
ifa_flags |= IFA_F_NOPREFIXROUTE;
|
2010-05-25 22:16:09 +05:30
|
|
|
} else {
|
2013-07-15 08:45:46 +05:30
|
|
|
/* local (specified or assumed) */
|
2020-06-29 21:27:26 +05:30
|
|
|
if ((int)arg >= 0)
|
|
|
|
NEXT_ARG();
|
2010-05-25 22:16:09 +05:30
|
|
|
if (local_len) {
|
|
|
|
duparg2("local", *argv);
|
|
|
|
}
|
|
|
|
get_prefix(&lcl, *argv, req.ifa.ifa_family);
|
|
|
|
if (req.ifa.ifa_family == AF_UNSPEC) {
|
|
|
|
req.ifa.ifa_family = lcl.family;
|
|
|
|
}
|
|
|
|
addattr_l(&req.n, sizeof(req), IFA_LOCAL, &lcl.data, lcl.bytelen);
|
|
|
|
local_len = lcl.bytelen;
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
2002-12-02 07:10:05 +05:30
|
|
|
argv++;
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
2002-12-02 07:10:05 +05:30
|
|
|
|
2020-06-29 21:27:25 +05:30
|
|
|
if (ifa_flags <= 0xff)
|
|
|
|
req.ifa.ifa_flags = ifa_flags;
|
|
|
|
else
|
|
|
|
addattr32(&req.n, sizeof(req), IFA_FLAGS, ifa_flags);
|
|
|
|
|
2010-07-04 07:25:43 +05:30
|
|
|
if (!d) {
|
|
|
|
/* There was no "dev IFACE", but we need that */
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("need \"dev IFACE\"");
|
2010-07-04 07:25:43 +05:30
|
|
|
}
|
2015-03-12 22:18:34 +05:30
|
|
|
if (l && !is_prefixed_with(l, d)) {
|
2006-02-22 22:31:00 +05:30
|
|
|
bb_error_msg_and_die("\"dev\" (%s) must match \"label\" (%s)", d, l);
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if (peer_len == 0 && local_len && cmd != RTM_DELADDR) {
|
|
|
|
peer = lcl;
|
|
|
|
addattr_l(&req.n, sizeof(req), IFA_ADDRESS, &lcl.data, lcl.bytelen);
|
|
|
|
}
|
|
|
|
if (req.ifa.ifa_prefixlen == 0)
|
|
|
|
req.ifa.ifa_prefixlen = lcl.bitlen;
|
|
|
|
|
|
|
|
if (brd_len < 0 && cmd != RTM_DELADDR) {
|
|
|
|
inet_prefix brd;
|
|
|
|
int i;
|
|
|
|
if (req.ifa.ifa_family != AF_INET) {
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("broadcast can be set only for IPv4 addresses");
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
|
|
|
brd = peer;
|
|
|
|
if (brd.bitlen <= 30) {
|
2013-07-15 08:45:46 +05:30
|
|
|
for (i = 31; i >= brd.bitlen; i--) {
|
2002-11-10 07:03:55 +05:30
|
|
|
if (brd_len == -1)
|
|
|
|
brd.data[0] |= htonl(1<<(31-i));
|
|
|
|
else
|
|
|
|
brd.data[0] &= ~htonl(1<<(31-i));
|
|
|
|
}
|
|
|
|
addattr_l(&req.n, sizeof(req), IFA_BROADCAST, &brd.data, brd.bytelen);
|
|
|
|
brd_len = brd.bytelen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!scoped && cmd != RTM_DELADDR)
|
|
|
|
req.ifa.ifa_scope = default_scope(&lcl);
|
|
|
|
|
2007-04-12 17:04:39 +05:30
|
|
|
xrtnl_open(&rth);
|
2002-11-10 07:03:55 +05:30
|
|
|
|
|
|
|
ll_init_map(&rth);
|
|
|
|
|
2007-04-12 17:04:39 +05:30
|
|
|
req.ifa.ifa_index = xll_name_to_index(d);
|
2002-11-10 07:03:55 +05:30
|
|
|
|
2020-06-29 21:27:26 +05:30
|
|
|
if (valid_lftp || preferred_lftp) {
|
|
|
|
struct ifa_cacheinfo cinfo = {};
|
|
|
|
|
|
|
|
if (!valid_lft) {
|
|
|
|
fprintf(stderr, "valid_lft is zero\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (valid_lft < preferred_lft) {
|
|
|
|
fprintf(stderr, "preferred_lft is greater than valid_lft\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cinfo.ifa_prefered = preferred_lft;
|
|
|
|
cinfo.ifa_valid = valid_lft;
|
|
|
|
addattr_l(&req.n, sizeof(req), IFA_CACHEINFO, &cinfo,
|
|
|
|
sizeof(cinfo));
|
|
|
|
}
|
|
|
|
|
2002-11-10 07:03:55 +05:30
|
|
|
if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0)
|
2007-04-07 06:44:45 +05:30
|
|
|
return 2;
|
2002-11-10 07:03:55 +05:30
|
|
|
|
2007-04-07 06:44:45 +05:30
|
|
|
return 0;
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
|
|
|
|
2007-04-07 06:44:45 +05:30
|
|
|
/* Return value becomes exitcode. It's okay to not return at all */
|
2010-07-25 02:57:38 +05:30
|
|
|
int FAST_FUNC do_ipaddr(char **argv)
|
2002-11-10 07:03:55 +05:30
|
|
|
{
|
2007-08-13 02:28:27 +05:30
|
|
|
static const char commands[] ALIGN1 =
|
2015-05-20 18:57:44 +05:30
|
|
|
/* 0 1 2 3 4 5 6 7 8 */
|
|
|
|
"add\0""change\0""chg\0""replace\0""delete\0""list\0""show\0""lst\0""flush\0";
|
2013-07-15 08:45:46 +05:30
|
|
|
int cmd = 2;
|
2016-04-21 22:08:51 +05:30
|
|
|
|
|
|
|
INIT_G();
|
|
|
|
|
2002-12-02 07:10:05 +05:30
|
|
|
if (*argv) {
|
2010-05-25 21:12:01 +05:30
|
|
|
cmd = index_in_substrings(commands, *argv);
|
2013-07-15 08:45:46 +05:30
|
|
|
if (cmd < 0)
|
2015-10-14 16:51:01 +05:30
|
|
|
invarg_1_to_2(*argv, applet_name);
|
2007-11-19 04:26:25 +05:30
|
|
|
argv++;
|
2015-07-01 22:06:06 +05:30
|
|
|
if (cmd <= 4) {
|
|
|
|
return ipaddr_modify(
|
|
|
|
/*cmd:*/ cmd == 4 ? RTM_DELADDR : RTM_NEWADDR,
|
|
|
|
/*flags:*/
|
|
|
|
cmd == 0 ? NLM_F_CREATE|NLM_F_EXCL : /* add */
|
|
|
|
cmd == 1 || cmd == 2 ? NLM_F_REPLACE : /* change */
|
|
|
|
cmd == 3 ? NLM_F_CREATE|NLM_F_REPLACE : /* replace */
|
|
|
|
0 /* delete */
|
|
|
|
, argv);
|
|
|
|
}
|
2015-05-20 18:57:44 +05:30
|
|
|
}
|
|
|
|
return ipaddr_list_or_flush(argv, cmd == 8);
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|