2023-01-11 10:53:46 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2005-03-23 00:13:21 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C)2005 USAGI/WIDE Project
|
2006-12-06 02:10:22 +08:00
|
|
|
*
|
2005-03-23 00:13:21 +08:00
|
|
|
* based on ipmonitor.c
|
2023-01-11 10:53:46 +08:00
|
|
|
*
|
2005-03-23 00:13:21 +08:00
|
|
|
* Authors:
|
|
|
|
* Masahide NAKAMURA @USAGI
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2015-04-11 04:17:54 +08:00
|
|
|
#include <netinet/in.h>
|
|
|
|
|
2005-03-23 00:13:21 +08:00
|
|
|
#include "utils.h"
|
|
|
|
#include "xfrm.h"
|
|
|
|
#include "ip_common.h"
|
|
|
|
|
|
|
|
static void usage(void) __attribute__((noreturn));
|
2018-11-16 06:36:28 +08:00
|
|
|
static int listen_all_nsid;
|
2019-01-19 03:12:17 +08:00
|
|
|
static bool nokeys;
|
2005-03-23 00:13:21 +08:00
|
|
|
|
|
|
|
static void usage(void)
|
|
|
|
{
|
treewide: refactor help messages
Every tool in the iproute2 package have one or more function to show
an help message to the user. Some of these functions print the help
line by line with a series of printf call, e.g. ip/xfrm_state.c does
60 fprintf calls.
If we group all the calls to a single one and just concatenate strings,
we save a lot of libc calls and thus object size. The size difference
of the compiled binaries calculated with bloat-o-meter is:
ip/ip:
add/remove: 0/0 grow/shrink: 5/15 up/down: 103/-4796 (-4693)
Total: Before=672591, After=667898, chg -0.70%
ip/rtmon:
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-54 (-54)
Total: Before=48879, After=48825, chg -0.11%
tc/tc:
add/remove: 0/2 grow/shrink: 31/10 up/down: 882/-6133 (-5251)
Total: Before=351912, After=346661, chg -1.49%
bridge/bridge:
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-459 (-459)
Total: Before=70502, After=70043, chg -0.65%
misc/lnstat:
add/remove: 0/1 grow/shrink: 1/0 up/down: 48/-486 (-438)
Total: Before=9960, After=9522, chg -4.40%
tipc/tipc:
add/remove: 0/0 grow/shrink: 1/1 up/down: 18/-62 (-44)
Total: Before=79182, After=79138, chg -0.06%
While at it, indent some strings which were starting at column 0,
and use tabs where possible, to have a consistent style across helps.
Signed-off-by: Matteo Croce <mcroce@redhat.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
2019-05-17 21:38:28 +08:00
|
|
|
fprintf(stderr,
|
|
|
|
"Usage: ip xfrm monitor [ nokeys ] [ all-nsid ] [ all | OBJECTS | help ]\n"
|
|
|
|
"OBJECTS := { acquire | expire | SA | aevent | policy | report }\n");
|
2005-03-23 00:13:21 +08:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
2018-10-20 04:42:36 +08:00
|
|
|
static int xfrm_acquire_print(struct nlmsghdr *n, void *arg)
|
2005-03-23 00:13:21 +08:00
|
|
|
{
|
2016-03-22 02:52:19 +08:00
|
|
|
FILE *fp = (FILE *)arg;
|
2005-03-23 00:13:21 +08:00
|
|
|
struct xfrm_user_acquire *xacq = NLMSG_DATA(n);
|
|
|
|
int len = n->nlmsg_len;
|
2016-03-22 02:52:19 +08:00
|
|
|
struct rtattr *tb[XFRMA_MAX+1];
|
2005-03-23 00:13:21 +08:00
|
|
|
__u16 family;
|
|
|
|
|
|
|
|
len -= NLMSG_LENGTH(sizeof(*xacq));
|
|
|
|
if (len < 0) {
|
|
|
|
fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
parse_rtattr(tb, XFRMA_MAX, XFRMACQ_RTA(xacq), len);
|
2005-06-08 05:55:55 +08:00
|
|
|
|
2005-03-23 00:13:21 +08:00
|
|
|
family = xacq->sel.family;
|
|
|
|
if (family == AF_UNSPEC)
|
|
|
|
family = xacq->policy.sel.family;
|
|
|
|
if (family == AF_UNSPEC)
|
|
|
|
family = preferred_family;
|
|
|
|
|
|
|
|
fprintf(fp, "acquire ");
|
|
|
|
|
|
|
|
fprintf(fp, "proto %s ", strxf_xfrmproto(xacq->id.proto));
|
|
|
|
if (show_stats > 0 || xacq->id.spi) {
|
|
|
|
__u32 spi = ntohl(xacq->id.spi);
|
2016-03-22 02:52:19 +08:00
|
|
|
|
2005-03-23 00:13:21 +08:00
|
|
|
fprintf(fp, "spi 0x%08x", spi);
|
|
|
|
if (show_stats > 0)
|
|
|
|
fprintf(fp, "(%u)", spi);
|
|
|
|
fprintf(fp, " ");
|
|
|
|
}
|
|
|
|
fprintf(fp, "%s", _SL_);
|
|
|
|
|
|
|
|
xfrm_selector_print(&xacq->sel, family, fp, " sel ");
|
|
|
|
|
|
|
|
xfrm_policy_info_print(&xacq->policy, tb, fp, " ", " policy ");
|
|
|
|
|
|
|
|
if (show_stats > 0)
|
|
|
|
fprintf(fp, " seq 0x%08u ", xacq->seq);
|
|
|
|
if (show_stats > 0) {
|
|
|
|
fprintf(fp, "%s-mask %s ",
|
|
|
|
strxf_algotype(XFRMA_ALG_CRYPT),
|
|
|
|
strxf_mask32(xacq->ealgos));
|
|
|
|
fprintf(fp, "%s-mask %s ",
|
|
|
|
strxf_algotype(XFRMA_ALG_AUTH),
|
|
|
|
strxf_mask32(xacq->aalgos));
|
|
|
|
fprintf(fp, "%s-mask %s",
|
|
|
|
strxf_algotype(XFRMA_ALG_COMP),
|
|
|
|
strxf_mask32(xacq->calgos));
|
|
|
|
}
|
|
|
|
fprintf(fp, "%s", _SL_);
|
|
|
|
|
|
|
|
if (oneline)
|
|
|
|
fprintf(fp, "\n");
|
2005-11-08 02:39:30 +08:00
|
|
|
fflush(fp);
|
2005-03-23 00:13:21 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-20 04:42:36 +08:00
|
|
|
static int xfrm_state_flush_print(struct nlmsghdr *n, void *arg)
|
2007-08-24 10:05:24 +08:00
|
|
|
{
|
2016-03-22 02:52:19 +08:00
|
|
|
FILE *fp = (FILE *)arg;
|
2007-08-24 10:05:24 +08:00
|
|
|
struct xfrm_usersa_flush *xsf = NLMSG_DATA(n);
|
|
|
|
int len = n->nlmsg_len;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
len -= NLMSG_SPACE(sizeof(*xsf));
|
|
|
|
if (len < 0) {
|
|
|
|
fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fp, "Flushed state ");
|
|
|
|
|
|
|
|
str = strxf_xfrmproto(xsf->proto);
|
|
|
|
if (str)
|
|
|
|
fprintf(fp, "proto %s", str);
|
|
|
|
else
|
|
|
|
fprintf(fp, "proto %u", xsf->proto);
|
|
|
|
fprintf(fp, "%s", _SL_);
|
|
|
|
|
|
|
|
if (oneline)
|
|
|
|
fprintf(fp, "\n");
|
|
|
|
fflush(fp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-20 04:42:36 +08:00
|
|
|
static int xfrm_policy_flush_print(struct nlmsghdr *n, void *arg)
|
2007-08-24 10:05:24 +08:00
|
|
|
{
|
2016-03-22 02:52:19 +08:00
|
|
|
struct rtattr *tb[XFRMA_MAX+1];
|
|
|
|
FILE *fp = (FILE *)arg;
|
2007-08-24 10:05:24 +08:00
|
|
|
int len = n->nlmsg_len;
|
|
|
|
|
|
|
|
len -= NLMSG_SPACE(0);
|
|
|
|
if (len < 0) {
|
|
|
|
fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fp, "Flushed policy ");
|
|
|
|
|
|
|
|
parse_rtattr(tb, XFRMA_MAX, NLMSG_DATA(n), len);
|
|
|
|
|
|
|
|
if (tb[XFRMA_POLICY_TYPE]) {
|
|
|
|
struct xfrm_userpolicy_type *upt;
|
|
|
|
|
|
|
|
fprintf(fp, "ptype ");
|
|
|
|
|
|
|
|
if (RTA_PAYLOAD(tb[XFRMA_POLICY_TYPE]) < sizeof(*upt))
|
|
|
|
fprintf(fp, "(ERROR truncated)");
|
|
|
|
|
2017-02-25 00:56:38 +08:00
|
|
|
upt = RTA_DATA(tb[XFRMA_POLICY_TYPE]);
|
2007-08-24 10:05:24 +08:00
|
|
|
fprintf(fp, "%s ", strxf_ptype(upt->type));
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fp, "%s", _SL_);
|
|
|
|
|
|
|
|
if (oneline)
|
|
|
|
fprintf(fp, "\n");
|
|
|
|
fflush(fp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-20 04:42:36 +08:00
|
|
|
static int xfrm_report_print(struct nlmsghdr *n, void *arg)
|
2006-12-05 18:16:05 +08:00
|
|
|
{
|
2016-03-22 02:52:19 +08:00
|
|
|
FILE *fp = (FILE *)arg;
|
2006-12-05 18:16:05 +08:00
|
|
|
struct xfrm_user_report *xrep = NLMSG_DATA(n);
|
|
|
|
int len = n->nlmsg_len;
|
2016-03-22 02:52:19 +08:00
|
|
|
struct rtattr *tb[XFRMA_MAX+1];
|
2006-12-05 18:16:05 +08:00
|
|
|
__u16 family;
|
|
|
|
|
|
|
|
len -= NLMSG_LENGTH(sizeof(*xrep));
|
|
|
|
if (len < 0) {
|
|
|
|
fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
family = xrep->sel.family;
|
|
|
|
if (family == AF_UNSPEC)
|
|
|
|
family = preferred_family;
|
|
|
|
|
|
|
|
fprintf(fp, "report ");
|
|
|
|
|
|
|
|
fprintf(fp, "proto %s ", strxf_xfrmproto(xrep->proto));
|
|
|
|
fprintf(fp, "%s", _SL_);
|
|
|
|
|
|
|
|
xfrm_selector_print(&xrep->sel, family, fp, " sel ");
|
|
|
|
|
|
|
|
parse_rtattr(tb, XFRMA_MAX, XFRMREP_RTA(xrep), len);
|
|
|
|
|
2022-12-12 15:54:06 +08:00
|
|
|
xfrm_xfrma_print(tb, family, fp, " ", nokeys, true);
|
2006-12-05 18:16:05 +08:00
|
|
|
|
|
|
|
if (oneline)
|
|
|
|
fprintf(fp, "\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-13 03:09:03 +08:00
|
|
|
static void xfrm_ae_flags_print(__u32 flags, void *arg)
|
2006-12-08 09:31:14 +08:00
|
|
|
{
|
2016-03-22 02:52:19 +08:00
|
|
|
FILE *fp = (FILE *)arg;
|
|
|
|
|
2006-12-08 09:31:14 +08:00
|
|
|
fprintf(fp, " (0x%x) ", flags);
|
|
|
|
if (!flags)
|
|
|
|
return;
|
|
|
|
if (flags & XFRM_AE_CR)
|
|
|
|
fprintf(fp, " replay update ");
|
|
|
|
if (flags & XFRM_AE_CE)
|
|
|
|
fprintf(fp, " timer expired ");
|
|
|
|
if (flags & XFRM_AE_CU)
|
|
|
|
fprintf(fp, " policy updated ");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-13 20:35:25 +08:00
|
|
|
static void xfrm_usersa_print(const struct xfrm_usersa_id *sa_id, __u32 reqid, FILE *fp)
|
|
|
|
{
|
2014-08-05 01:30:35 +08:00
|
|
|
fprintf(fp, "dst %s ",
|
2016-03-23 02:35:16 +08:00
|
|
|
rt_addr_n2a(sa_id->family, sizeof(sa_id->daddr), &sa_id->daddr));
|
2012-03-13 20:35:25 +08:00
|
|
|
|
|
|
|
fprintf(fp, " reqid 0x%x", reqid);
|
|
|
|
|
|
|
|
fprintf(fp, " protocol %s ", strxf_proto(sa_id->proto));
|
|
|
|
fprintf(fp, " SPI 0x%x", ntohl(sa_id->spi));
|
|
|
|
}
|
|
|
|
|
2018-10-20 04:42:36 +08:00
|
|
|
static int xfrm_ae_print(struct nlmsghdr *n, void *arg)
|
2006-12-08 09:31:14 +08:00
|
|
|
{
|
2016-03-22 02:52:19 +08:00
|
|
|
FILE *fp = (FILE *)arg;
|
2006-12-08 09:31:14 +08:00
|
|
|
struct xfrm_aevent_id *id = NLMSG_DATA(n);
|
|
|
|
|
|
|
|
fprintf(fp, "Async event ");
|
|
|
|
xfrm_ae_flags_print(id->flags, arg);
|
2016-03-22 02:52:19 +08:00
|
|
|
fprintf(fp, "\n\t");
|
2015-03-16 03:48:32 +08:00
|
|
|
fprintf(fp, "src %s ", rt_addr_n2a(id->sa_id.family,
|
2016-03-23 02:35:16 +08:00
|
|
|
sizeof(id->saddr), &id->saddr));
|
2012-03-13 20:35:25 +08:00
|
|
|
|
|
|
|
xfrm_usersa_print(&id->sa_id, id->reqid, fp);
|
2006-12-08 09:31:14 +08:00
|
|
|
|
|
|
|
fprintf(fp, "\n");
|
|
|
|
fflush(fp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-05 01:30:35 +08:00
|
|
|
static void xfrm_print_addr(FILE *fp, int family, xfrm_address_t *a)
|
2012-03-13 20:35:25 +08:00
|
|
|
{
|
2016-03-23 02:35:16 +08:00
|
|
|
fprintf(fp, "%s", rt_addr_n2a(family, sizeof(*a), a));
|
2012-03-13 20:35:25 +08:00
|
|
|
}
|
|
|
|
|
2018-10-20 04:42:36 +08:00
|
|
|
static int xfrm_mapping_print(struct nlmsghdr *n, void *arg)
|
2012-03-13 20:35:25 +08:00
|
|
|
{
|
2016-03-22 02:52:19 +08:00
|
|
|
FILE *fp = (FILE *)arg;
|
2012-03-13 20:35:25 +08:00
|
|
|
struct xfrm_user_mapping *map = NLMSG_DATA(n);
|
|
|
|
|
|
|
|
fprintf(fp, "Mapping change ");
|
2014-08-05 01:30:35 +08:00
|
|
|
xfrm_print_addr(fp, map->id.family, &map->old_saddr);
|
2012-03-13 20:35:25 +08:00
|
|
|
|
|
|
|
fprintf(fp, ":%d -> ", ntohs(map->old_sport));
|
2014-08-05 01:30:35 +08:00
|
|
|
xfrm_print_addr(fp, map->id.family, &map->new_saddr);
|
2012-03-13 20:35:25 +08:00
|
|
|
fprintf(fp, ":%d\n\t", ntohs(map->new_sport));
|
|
|
|
|
|
|
|
xfrm_usersa_print(&map->id, map->reqid, fp);
|
|
|
|
|
|
|
|
fprintf(fp, "\n");
|
|
|
|
fflush(fp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-20 04:42:36 +08:00
|
|
|
static int xfrm_accept_msg(struct rtnl_ctrl_data *ctrl,
|
2005-03-23 00:13:21 +08:00
|
|
|
struct nlmsghdr *n, void *arg)
|
|
|
|
{
|
2016-03-22 02:52:19 +08:00
|
|
|
FILE *fp = (FILE *)arg;
|
2005-03-23 00:13:21 +08:00
|
|
|
|
2005-06-08 05:55:55 +08:00
|
|
|
if (timestamp)
|
|
|
|
print_timestamp(fp);
|
|
|
|
|
2015-05-20 22:20:01 +08:00
|
|
|
if (listen_all_nsid) {
|
|
|
|
if (ctrl == NULL || ctrl->nsid < 0)
|
|
|
|
fprintf(fp, "[nsid current]");
|
|
|
|
else
|
|
|
|
fprintf(fp, "[nsid %d]", ctrl->nsid);
|
|
|
|
}
|
|
|
|
|
2007-08-24 10:05:24 +08:00
|
|
|
switch (n->nlmsg_type) {
|
|
|
|
case XFRM_MSG_NEWSA:
|
|
|
|
case XFRM_MSG_DELSA:
|
|
|
|
case XFRM_MSG_UPDSA:
|
|
|
|
case XFRM_MSG_EXPIRE:
|
2018-10-20 04:42:36 +08:00
|
|
|
xfrm_state_print(n, arg);
|
2005-11-02 07:03:03 +08:00
|
|
|
return 0;
|
2007-08-24 10:05:24 +08:00
|
|
|
case XFRM_MSG_NEWPOLICY:
|
|
|
|
case XFRM_MSG_DELPOLICY:
|
|
|
|
case XFRM_MSG_UPDPOLICY:
|
|
|
|
case XFRM_MSG_POLEXPIRE:
|
2018-10-20 04:42:36 +08:00
|
|
|
xfrm_policy_print(n, arg);
|
2005-11-02 07:03:03 +08:00
|
|
|
return 0;
|
2007-08-24 10:05:24 +08:00
|
|
|
case XFRM_MSG_ACQUIRE:
|
2018-10-20 04:42:36 +08:00
|
|
|
xfrm_acquire_print(n, arg);
|
2005-03-23 00:13:21 +08:00
|
|
|
return 0;
|
2007-08-24 10:05:24 +08:00
|
|
|
case XFRM_MSG_FLUSHSA:
|
2018-10-20 04:42:36 +08:00
|
|
|
xfrm_state_flush_print(n, arg);
|
2005-03-23 00:13:21 +08:00
|
|
|
return 0;
|
2007-08-24 10:05:24 +08:00
|
|
|
case XFRM_MSG_FLUSHPOLICY:
|
2018-10-20 04:42:36 +08:00
|
|
|
xfrm_policy_flush_print(n, arg);
|
2005-03-23 00:13:21 +08:00
|
|
|
return 0;
|
2007-08-24 10:05:24 +08:00
|
|
|
case XFRM_MSG_REPORT:
|
2018-10-20 04:42:36 +08:00
|
|
|
xfrm_report_print(n, arg);
|
2006-12-05 18:16:05 +08:00
|
|
|
return 0;
|
2007-08-24 10:05:24 +08:00
|
|
|
case XFRM_MSG_NEWAE:
|
2018-10-20 04:42:36 +08:00
|
|
|
xfrm_ae_print(n, arg);
|
2006-12-08 09:31:14 +08:00
|
|
|
return 0;
|
2012-03-13 20:35:25 +08:00
|
|
|
case XFRM_MSG_MAPPING:
|
2018-10-20 04:42:36 +08:00
|
|
|
xfrm_mapping_print(n, arg);
|
2012-03-13 20:35:25 +08:00
|
|
|
return 0;
|
2021-10-25 16:17:06 +08:00
|
|
|
case XFRM_MSG_GETDEFAULT:
|
|
|
|
xfrm_policy_default_print(n, arg);
|
|
|
|
return 0;
|
2007-08-24 10:05:24 +08:00
|
|
|
default:
|
|
|
|
break;
|
2006-12-08 09:31:14 +08:00
|
|
|
}
|
2007-08-24 10:05:24 +08:00
|
|
|
|
2005-03-23 00:13:21 +08:00
|
|
|
if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP &&
|
|
|
|
n->nlmsg_type != NLMSG_DONE) {
|
2005-11-02 07:03:03 +08:00
|
|
|
fprintf(fp, "Unknown message: %08d 0x%08x 0x%08x\n",
|
2005-03-23 00:13:21 +08:00
|
|
|
n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-26 08:27:37 +08:00
|
|
|
extern struct rtnl_handle rth;
|
|
|
|
|
2005-03-23 00:13:21 +08:00
|
|
|
int do_xfrm_monitor(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *file = NULL;
|
2016-03-22 02:52:19 +08:00
|
|
|
unsigned int groups = ~((unsigned)0); /* XXX */
|
|
|
|
int lacquire = 0;
|
|
|
|
int lexpire = 0;
|
|
|
|
int laevent = 0;
|
|
|
|
int lpolicy = 0;
|
|
|
|
int lsa = 0;
|
|
|
|
int lreport = 0;
|
2005-03-23 00:13:21 +08:00
|
|
|
|
2006-09-26 08:27:37 +08:00
|
|
|
rtnl_close(&rth);
|
|
|
|
|
2005-03-23 00:13:21 +08:00
|
|
|
while (argc > 0) {
|
|
|
|
if (matches(*argv, "file") == 0) {
|
|
|
|
NEXT_ARG();
|
|
|
|
file = *argv;
|
2019-01-19 03:12:17 +08:00
|
|
|
} else if (strcmp(*argv, "nokeys") == 0) {
|
|
|
|
nokeys = true;
|
2018-05-31 03:11:32 +08:00
|
|
|
} else if (strcmp(*argv, "all") == 0) {
|
|
|
|
/* fall out */
|
2015-05-20 22:20:01 +08:00
|
|
|
} else if (matches(*argv, "all-nsid") == 0) {
|
|
|
|
listen_all_nsid = 1;
|
2005-03-23 00:13:21 +08:00
|
|
|
} else if (matches(*argv, "acquire") == 0) {
|
2016-03-22 02:52:19 +08:00
|
|
|
lacquire = 1;
|
2005-03-23 00:13:21 +08:00
|
|
|
groups = 0;
|
|
|
|
} else if (matches(*argv, "expire") == 0) {
|
2016-03-22 02:52:19 +08:00
|
|
|
lexpire = 1;
|
2005-03-23 00:13:21 +08:00
|
|
|
groups = 0;
|
2005-11-02 07:03:03 +08:00
|
|
|
} else if (matches(*argv, "SA") == 0) {
|
2016-03-22 02:52:19 +08:00
|
|
|
lsa = 1;
|
2005-11-02 07:03:03 +08:00
|
|
|
groups = 0;
|
2006-12-08 09:31:14 +08:00
|
|
|
} else if (matches(*argv, "aevent") == 0) {
|
2016-03-22 02:52:19 +08:00
|
|
|
laevent = 1;
|
2006-12-08 09:31:14 +08:00
|
|
|
groups = 0;
|
2005-11-02 07:03:03 +08:00
|
|
|
} else if (matches(*argv, "policy") == 0) {
|
2016-03-22 02:52:19 +08:00
|
|
|
lpolicy = 1;
|
2005-11-02 07:03:03 +08:00
|
|
|
groups = 0;
|
2006-12-05 18:16:05 +08:00
|
|
|
} else if (matches(*argv, "report") == 0) {
|
2016-03-22 02:52:19 +08:00
|
|
|
lreport = 1;
|
2006-12-05 18:16:05 +08:00
|
|
|
groups = 0;
|
2005-03-23 00:13:21 +08:00
|
|
|
} else if (matches(*argv, "help") == 0) {
|
|
|
|
usage();
|
2018-05-31 03:11:32 +08:00
|
|
|
} else {
|
2005-03-23 00:13:21 +08:00
|
|
|
fprintf(stderr, "Argument \"%s\" is unknown, try \"ip xfrm monitor help\".\n", *argv);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
argc--; argv++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lacquire)
|
2006-12-08 09:58:23 +08:00
|
|
|
groups |= nl_mgrp(XFRMNLGRP_ACQUIRE);
|
2005-03-23 00:13:21 +08:00
|
|
|
if (lexpire)
|
2006-12-08 09:58:23 +08:00
|
|
|
groups |= nl_mgrp(XFRMNLGRP_EXPIRE);
|
2005-11-02 07:03:03 +08:00
|
|
|
if (lsa)
|
2006-12-08 09:58:23 +08:00
|
|
|
groups |= nl_mgrp(XFRMNLGRP_SA);
|
2005-11-02 07:03:03 +08:00
|
|
|
if (lpolicy)
|
2006-12-08 09:58:23 +08:00
|
|
|
groups |= nl_mgrp(XFRMNLGRP_POLICY);
|
2006-12-08 09:31:14 +08:00
|
|
|
if (laevent)
|
2006-12-08 09:58:23 +08:00
|
|
|
groups |= nl_mgrp(XFRMNLGRP_AEVENTS);
|
2006-12-05 18:16:05 +08:00
|
|
|
if (lreport)
|
2006-12-08 09:58:23 +08:00
|
|
|
groups |= nl_mgrp(XFRMNLGRP_REPORT);
|
2005-03-23 00:13:21 +08:00
|
|
|
|
|
|
|
if (file) {
|
|
|
|
FILE *fp;
|
2015-12-31 09:19:04 +08:00
|
|
|
int err;
|
|
|
|
|
2005-03-23 00:13:21 +08:00
|
|
|
fp = fopen(file, "r");
|
|
|
|
if (fp == NULL) {
|
|
|
|
perror("Cannot fopen");
|
|
|
|
exit(-1);
|
|
|
|
}
|
2015-12-31 09:19:04 +08:00
|
|
|
err = rtnl_from_file(fp, xfrm_accept_msg, stdout);
|
|
|
|
fclose(fp);
|
|
|
|
return err;
|
2005-03-23 00:13:21 +08:00
|
|
|
}
|
|
|
|
|
2005-11-02 07:03:03 +08:00
|
|
|
if (rtnl_open_byproto(&rth, groups, NETLINK_XFRM) < 0)
|
|
|
|
exit(1);
|
2015-05-20 22:20:01 +08:00
|
|
|
if (listen_all_nsid && rtnl_listen_all_nsid(&rth) < 0)
|
|
|
|
exit(1);
|
2005-11-02 07:03:03 +08:00
|
|
|
|
2016-03-22 02:52:19 +08:00
|
|
|
if (rtnl_listen(&rth, xfrm_accept_msg, (void *)stdout) < 0)
|
2005-03-23 00:13:21 +08:00
|
|
|
exit(2);
|
|
|
|
|
2005-09-02 03:21:50 +08:00
|
|
|
return 0;
|
2005-03-23 00:13:21 +08:00
|
|
|
}
|