linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 1 | /* $USAGI: $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (C)2005 USAGI/WIDE Project |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 5 | * |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 10 | * |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 15 | * |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License |
Stephen Hemminger | 4d98ab0 | 2013-12-06 15:05:07 -0800 | [diff] [blame] | 17 | * along with this program; if not, see <http://www.gnu.org/licenses>. |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 18 | */ |
| 19 | /* |
| 20 | * based on ipmonitor.c |
| 21 | */ |
| 22 | /* |
| 23 | * Authors: |
| 24 | * Masahide NAKAMURA @USAGI |
| 25 | */ |
| 26 | |
| 27 | #include <stdio.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
| 30 | #include <linux/xfrm.h> |
| 31 | #include "utils.h" |
| 32 | #include "xfrm.h" |
| 33 | #include "ip_common.h" |
| 34 | |
| 35 | static void usage(void) __attribute__((noreturn)); |
| 36 | |
| 37 | static void usage(void) |
| 38 | { |
Vadim Kochan | c16298b | 2015-02-14 20:07:44 +0200 | [diff] [blame] | 39 | fprintf(stderr, "Usage: ip xfrm monitor [ all | OBJECTS | help ]\n"); |
| 40 | fprintf(stderr, "OBJECTS := { acquire | expire | SA | aevent | policy | report }\n"); |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 41 | exit(-1); |
| 42 | } |
| 43 | |
| 44 | static int xfrm_acquire_print(const struct sockaddr_nl *who, |
| 45 | struct nlmsghdr *n, void *arg) |
| 46 | { |
| 47 | FILE *fp = (FILE*)arg; |
| 48 | struct xfrm_user_acquire *xacq = NLMSG_DATA(n); |
| 49 | int len = n->nlmsg_len; |
| 50 | struct rtattr * tb[XFRMA_MAX+1]; |
| 51 | __u16 family; |
| 52 | |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 53 | len -= NLMSG_LENGTH(sizeof(*xacq)); |
| 54 | if (len < 0) { |
| 55 | fprintf(stderr, "BUG: wrong nlmsg len %d\n", len); |
| 56 | return -1; |
| 57 | } |
| 58 | |
| 59 | parse_rtattr(tb, XFRMA_MAX, XFRMACQ_RTA(xacq), len); |
shemminger | 90f9302 | 2005-06-07 21:55:55 +0000 | [diff] [blame] | 60 | |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 61 | family = xacq->sel.family; |
| 62 | if (family == AF_UNSPEC) |
| 63 | family = xacq->policy.sel.family; |
| 64 | if (family == AF_UNSPEC) |
| 65 | family = preferred_family; |
| 66 | |
| 67 | fprintf(fp, "acquire "); |
| 68 | |
| 69 | fprintf(fp, "proto %s ", strxf_xfrmproto(xacq->id.proto)); |
| 70 | if (show_stats > 0 || xacq->id.spi) { |
| 71 | __u32 spi = ntohl(xacq->id.spi); |
| 72 | fprintf(fp, "spi 0x%08x", spi); |
| 73 | if (show_stats > 0) |
| 74 | fprintf(fp, "(%u)", spi); |
| 75 | fprintf(fp, " "); |
| 76 | } |
| 77 | fprintf(fp, "%s", _SL_); |
| 78 | |
| 79 | xfrm_selector_print(&xacq->sel, family, fp, " sel "); |
| 80 | |
| 81 | xfrm_policy_info_print(&xacq->policy, tb, fp, " ", " policy "); |
| 82 | |
| 83 | if (show_stats > 0) |
| 84 | fprintf(fp, " seq 0x%08u ", xacq->seq); |
| 85 | if (show_stats > 0) { |
| 86 | fprintf(fp, "%s-mask %s ", |
| 87 | strxf_algotype(XFRMA_ALG_CRYPT), |
| 88 | strxf_mask32(xacq->ealgos)); |
| 89 | fprintf(fp, "%s-mask %s ", |
| 90 | strxf_algotype(XFRMA_ALG_AUTH), |
| 91 | strxf_mask32(xacq->aalgos)); |
| 92 | fprintf(fp, "%s-mask %s", |
| 93 | strxf_algotype(XFRMA_ALG_COMP), |
| 94 | strxf_mask32(xacq->calgos)); |
| 95 | } |
| 96 | fprintf(fp, "%s", _SL_); |
| 97 | |
| 98 | if (oneline) |
| 99 | fprintf(fp, "\n"); |
shemminger | 669ae74 | 2005-11-07 18:39:30 +0000 | [diff] [blame] | 100 | fflush(fp); |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |
Masahide NAKAMURA | efe69c1 | 2007-08-24 11:05:24 +0900 | [diff] [blame] | 105 | static int xfrm_state_flush_print(const struct sockaddr_nl *who, |
| 106 | struct nlmsghdr *n, void *arg) |
| 107 | { |
| 108 | FILE *fp = (FILE*)arg; |
| 109 | struct xfrm_usersa_flush *xsf = NLMSG_DATA(n); |
| 110 | int len = n->nlmsg_len; |
| 111 | const char *str; |
| 112 | |
| 113 | len -= NLMSG_SPACE(sizeof(*xsf)); |
| 114 | if (len < 0) { |
| 115 | fprintf(stderr, "BUG: wrong nlmsg len %d\n", len); |
| 116 | return -1; |
| 117 | } |
| 118 | |
| 119 | fprintf(fp, "Flushed state "); |
| 120 | |
| 121 | str = strxf_xfrmproto(xsf->proto); |
| 122 | if (str) |
| 123 | fprintf(fp, "proto %s", str); |
| 124 | else |
| 125 | fprintf(fp, "proto %u", xsf->proto); |
| 126 | fprintf(fp, "%s", _SL_); |
| 127 | |
| 128 | if (oneline) |
| 129 | fprintf(fp, "\n"); |
| 130 | fflush(fp); |
| 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | static int xfrm_policy_flush_print(const struct sockaddr_nl *who, |
| 136 | struct nlmsghdr *n, void *arg) |
| 137 | { |
| 138 | struct rtattr * tb[XFRMA_MAX+1]; |
| 139 | FILE *fp = (FILE*)arg; |
| 140 | int len = n->nlmsg_len; |
| 141 | |
| 142 | len -= NLMSG_SPACE(0); |
| 143 | if (len < 0) { |
| 144 | fprintf(stderr, "BUG: wrong nlmsg len %d\n", len); |
| 145 | return -1; |
| 146 | } |
| 147 | |
| 148 | fprintf(fp, "Flushed policy "); |
| 149 | |
| 150 | parse_rtattr(tb, XFRMA_MAX, NLMSG_DATA(n), len); |
| 151 | |
| 152 | if (tb[XFRMA_POLICY_TYPE]) { |
| 153 | struct xfrm_userpolicy_type *upt; |
| 154 | |
| 155 | fprintf(fp, "ptype "); |
| 156 | |
| 157 | if (RTA_PAYLOAD(tb[XFRMA_POLICY_TYPE]) < sizeof(*upt)) |
| 158 | fprintf(fp, "(ERROR truncated)"); |
| 159 | |
| 160 | upt = (struct xfrm_userpolicy_type *)RTA_DATA(tb[XFRMA_POLICY_TYPE]); |
| 161 | fprintf(fp, "%s ", strxf_ptype(upt->type)); |
| 162 | } |
| 163 | |
| 164 | fprintf(fp, "%s", _SL_); |
| 165 | |
| 166 | if (oneline) |
| 167 | fprintf(fp, "\n"); |
| 168 | fflush(fp); |
| 169 | |
| 170 | return 0; |
| 171 | } |
| 172 | |
Masahide NAKAMURA | c54f31e | 2006-12-05 19:16:05 +0900 | [diff] [blame] | 173 | static int xfrm_report_print(const struct sockaddr_nl *who, |
| 174 | struct nlmsghdr *n, void *arg) |
| 175 | { |
| 176 | FILE *fp = (FILE*)arg; |
| 177 | struct xfrm_user_report *xrep = NLMSG_DATA(n); |
| 178 | int len = n->nlmsg_len; |
| 179 | struct rtattr * tb[XFRMA_MAX+1]; |
| 180 | __u16 family; |
| 181 | |
Masahide NAKAMURA | c54f31e | 2006-12-05 19:16:05 +0900 | [diff] [blame] | 182 | len -= NLMSG_LENGTH(sizeof(*xrep)); |
| 183 | if (len < 0) { |
| 184 | fprintf(stderr, "BUG: wrong nlmsg len %d\n", len); |
| 185 | return -1; |
| 186 | } |
| 187 | |
| 188 | family = xrep->sel.family; |
| 189 | if (family == AF_UNSPEC) |
| 190 | family = preferred_family; |
| 191 | |
| 192 | fprintf(fp, "report "); |
| 193 | |
| 194 | fprintf(fp, "proto %s ", strxf_xfrmproto(xrep->proto)); |
| 195 | fprintf(fp, "%s", _SL_); |
| 196 | |
| 197 | xfrm_selector_print(&xrep->sel, family, fp, " sel "); |
| 198 | |
| 199 | parse_rtattr(tb, XFRMA_MAX, XFRMREP_RTA(xrep), len); |
| 200 | |
| 201 | xfrm_xfrma_print(tb, family, fp, " "); |
| 202 | |
| 203 | if (oneline) |
| 204 | fprintf(fp, "\n"); |
| 205 | |
| 206 | return 0; |
| 207 | } |
| 208 | |
Stephen Hemminger | d1f28cf | 2013-02-12 11:09:03 -0800 | [diff] [blame] | 209 | static void xfrm_ae_flags_print(__u32 flags, void *arg) |
jamal | c9fd974 | 2006-12-07 20:31:14 -0500 | [diff] [blame] | 210 | { |
| 211 | FILE *fp = (FILE*)arg; |
| 212 | fprintf(fp, " (0x%x) ", flags); |
| 213 | if (!flags) |
| 214 | return; |
| 215 | if (flags & XFRM_AE_CR) |
| 216 | fprintf(fp, " replay update "); |
| 217 | if (flags & XFRM_AE_CE) |
| 218 | fprintf(fp, " timer expired "); |
| 219 | if (flags & XFRM_AE_CU) |
| 220 | fprintf(fp, " policy updated "); |
| 221 | |
| 222 | } |
| 223 | |
Florian Westphal | 598a42c | 2012-03-13 12:35:25 +0000 | [diff] [blame] | 224 | static void xfrm_usersa_print(const struct xfrm_usersa_id *sa_id, __u32 reqid, FILE *fp) |
| 225 | { |
| 226 | char buf[256]; |
| 227 | |
| 228 | buf[0] = 0; |
Stephen Hemminger | 656111b | 2014-08-04 10:30:35 -0700 | [diff] [blame] | 229 | fprintf(fp, "dst %s ", |
Eric W. Biederman | 26dcdf3 | 2015-03-15 14:48:32 -0500 | [diff] [blame^] | 230 | rt_addr_n2a(sa_id->family, sizeof(sa_id->daddr), &sa_id->daddr, |
| 231 | buf, sizeof(buf))); |
Florian Westphal | 598a42c | 2012-03-13 12:35:25 +0000 | [diff] [blame] | 232 | |
| 233 | fprintf(fp, " reqid 0x%x", reqid); |
| 234 | |
| 235 | fprintf(fp, " protocol %s ", strxf_proto(sa_id->proto)); |
| 236 | fprintf(fp, " SPI 0x%x", ntohl(sa_id->spi)); |
| 237 | } |
| 238 | |
jamal | c9fd974 | 2006-12-07 20:31:14 -0500 | [diff] [blame] | 239 | static int xfrm_ae_print(const struct sockaddr_nl *who, |
| 240 | struct nlmsghdr *n, void *arg) |
| 241 | { |
| 242 | FILE *fp = (FILE*)arg; |
| 243 | struct xfrm_aevent_id *id = NLMSG_DATA(n); |
| 244 | char abuf[256]; |
| 245 | |
| 246 | fprintf(fp, "Async event "); |
| 247 | xfrm_ae_flags_print(id->flags, arg); |
| 248 | fprintf(fp,"\n\t"); |
| 249 | memset(abuf, '\0', sizeof(abuf)); |
Eric W. Biederman | 26dcdf3 | 2015-03-15 14:48:32 -0500 | [diff] [blame^] | 250 | fprintf(fp, "src %s ", rt_addr_n2a(id->sa_id.family, |
| 251 | sizeof(id->saddr), &id->saddr, |
Stephen Hemminger | 656111b | 2014-08-04 10:30:35 -0700 | [diff] [blame] | 252 | abuf, sizeof(abuf))); |
Florian Westphal | 598a42c | 2012-03-13 12:35:25 +0000 | [diff] [blame] | 253 | |
| 254 | xfrm_usersa_print(&id->sa_id, id->reqid, fp); |
jamal | c9fd974 | 2006-12-07 20:31:14 -0500 | [diff] [blame] | 255 | |
| 256 | fprintf(fp, "\n"); |
| 257 | fflush(fp); |
| 258 | |
| 259 | return 0; |
| 260 | } |
| 261 | |
Stephen Hemminger | 656111b | 2014-08-04 10:30:35 -0700 | [diff] [blame] | 262 | static void xfrm_print_addr(FILE *fp, int family, xfrm_address_t *a) |
Florian Westphal | 598a42c | 2012-03-13 12:35:25 +0000 | [diff] [blame] | 263 | { |
| 264 | char buf[256]; |
| 265 | |
| 266 | buf[0] = 0; |
Eric W. Biederman | 26dcdf3 | 2015-03-15 14:48:32 -0500 | [diff] [blame^] | 267 | fprintf(fp, "%s", rt_addr_n2a(family, sizeof(*a), a, buf, sizeof(buf))); |
Florian Westphal | 598a42c | 2012-03-13 12:35:25 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | static int xfrm_mapping_print(const struct sockaddr_nl *who, |
| 271 | struct nlmsghdr *n, void *arg) |
| 272 | { |
| 273 | FILE *fp = (FILE*)arg; |
| 274 | struct xfrm_user_mapping *map = NLMSG_DATA(n); |
| 275 | |
| 276 | fprintf(fp, "Mapping change "); |
Stephen Hemminger | 656111b | 2014-08-04 10:30:35 -0700 | [diff] [blame] | 277 | xfrm_print_addr(fp, map->id.family, &map->old_saddr); |
Florian Westphal | 598a42c | 2012-03-13 12:35:25 +0000 | [diff] [blame] | 278 | |
| 279 | fprintf(fp, ":%d -> ", ntohs(map->old_sport)); |
Stephen Hemminger | 656111b | 2014-08-04 10:30:35 -0700 | [diff] [blame] | 280 | xfrm_print_addr(fp, map->id.family, &map->new_saddr); |
Florian Westphal | 598a42c | 2012-03-13 12:35:25 +0000 | [diff] [blame] | 281 | fprintf(fp, ":%d\n\t", ntohs(map->new_sport)); |
| 282 | |
| 283 | xfrm_usersa_print(&map->id, map->reqid, fp); |
| 284 | |
| 285 | fprintf(fp, "\n"); |
| 286 | fflush(fp); |
| 287 | return 0; |
| 288 | } |
| 289 | |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 290 | static int xfrm_accept_msg(const struct sockaddr_nl *who, |
| 291 | struct nlmsghdr *n, void *arg) |
| 292 | { |
| 293 | FILE *fp = (FILE*)arg; |
| 294 | |
shemminger | 90f9302 | 2005-06-07 21:55:55 +0000 | [diff] [blame] | 295 | if (timestamp) |
| 296 | print_timestamp(fp); |
| 297 | |
Masahide NAKAMURA | efe69c1 | 2007-08-24 11:05:24 +0900 | [diff] [blame] | 298 | switch (n->nlmsg_type) { |
| 299 | case XFRM_MSG_NEWSA: |
| 300 | case XFRM_MSG_DELSA: |
| 301 | case XFRM_MSG_UPDSA: |
| 302 | case XFRM_MSG_EXPIRE: |
shemminger | c595c79 | 2005-11-01 23:03:03 +0000 | [diff] [blame] | 303 | xfrm_state_print(who, n, arg); |
| 304 | return 0; |
Masahide NAKAMURA | efe69c1 | 2007-08-24 11:05:24 +0900 | [diff] [blame] | 305 | case XFRM_MSG_NEWPOLICY: |
| 306 | case XFRM_MSG_DELPOLICY: |
| 307 | case XFRM_MSG_UPDPOLICY: |
| 308 | case XFRM_MSG_POLEXPIRE: |
shemminger | c595c79 | 2005-11-01 23:03:03 +0000 | [diff] [blame] | 309 | xfrm_policy_print(who, n, arg); |
| 310 | return 0; |
Masahide NAKAMURA | efe69c1 | 2007-08-24 11:05:24 +0900 | [diff] [blame] | 311 | case XFRM_MSG_ACQUIRE: |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 312 | xfrm_acquire_print(who, n, arg); |
| 313 | return 0; |
Masahide NAKAMURA | efe69c1 | 2007-08-24 11:05:24 +0900 | [diff] [blame] | 314 | case XFRM_MSG_FLUSHSA: |
| 315 | xfrm_state_flush_print(who, n, arg); |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 316 | return 0; |
Masahide NAKAMURA | efe69c1 | 2007-08-24 11:05:24 +0900 | [diff] [blame] | 317 | case XFRM_MSG_FLUSHPOLICY: |
| 318 | xfrm_policy_flush_print(who, n, arg); |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 319 | return 0; |
Masahide NAKAMURA | efe69c1 | 2007-08-24 11:05:24 +0900 | [diff] [blame] | 320 | case XFRM_MSG_REPORT: |
Masahide NAKAMURA | c54f31e | 2006-12-05 19:16:05 +0900 | [diff] [blame] | 321 | xfrm_report_print(who, n, arg); |
| 322 | return 0; |
Masahide NAKAMURA | efe69c1 | 2007-08-24 11:05:24 +0900 | [diff] [blame] | 323 | case XFRM_MSG_NEWAE: |
jamal | c9fd974 | 2006-12-07 20:31:14 -0500 | [diff] [blame] | 324 | xfrm_ae_print(who, n, arg); |
| 325 | return 0; |
Florian Westphal | 598a42c | 2012-03-13 12:35:25 +0000 | [diff] [blame] | 326 | case XFRM_MSG_MAPPING: |
| 327 | xfrm_mapping_print(who, n, arg); |
| 328 | return 0; |
Masahide NAKAMURA | efe69c1 | 2007-08-24 11:05:24 +0900 | [diff] [blame] | 329 | default: |
| 330 | break; |
jamal | c9fd974 | 2006-12-07 20:31:14 -0500 | [diff] [blame] | 331 | } |
Masahide NAKAMURA | efe69c1 | 2007-08-24 11:05:24 +0900 | [diff] [blame] | 332 | |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 333 | if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP && |
| 334 | n->nlmsg_type != NLMSG_DONE) { |
shemminger | c595c79 | 2005-11-01 23:03:03 +0000 | [diff] [blame] | 335 | fprintf(fp, "Unknown message: %08d 0x%08x 0x%08x\n", |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 336 | n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); |
| 337 | } |
| 338 | return 0; |
| 339 | } |
| 340 | |
Stephen Hemminger | 7721971 | 2006-09-25 17:27:37 -0700 | [diff] [blame] | 341 | extern struct rtnl_handle rth; |
| 342 | |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 343 | int do_xfrm_monitor(int argc, char **argv) |
| 344 | { |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 345 | char *file = NULL; |
| 346 | unsigned groups = ~((unsigned)0); /* XXX */ |
| 347 | int lacquire=0; |
| 348 | int lexpire=0; |
jamal | c9fd974 | 2006-12-07 20:31:14 -0500 | [diff] [blame] | 349 | int laevent=0; |
shemminger | c595c79 | 2005-11-01 23:03:03 +0000 | [diff] [blame] | 350 | int lpolicy=0; |
| 351 | int lsa=0; |
Masahide NAKAMURA | c54f31e | 2006-12-05 19:16:05 +0900 | [diff] [blame] | 352 | int lreport=0; |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 353 | |
Stephen Hemminger | 7721971 | 2006-09-25 17:27:37 -0700 | [diff] [blame] | 354 | rtnl_close(&rth); |
| 355 | |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 356 | while (argc > 0) { |
| 357 | if (matches(*argv, "file") == 0) { |
| 358 | NEXT_ARG(); |
| 359 | file = *argv; |
| 360 | } else if (matches(*argv, "acquire") == 0) { |
| 361 | lacquire=1; |
| 362 | groups = 0; |
| 363 | } else if (matches(*argv, "expire") == 0) { |
| 364 | lexpire=1; |
| 365 | groups = 0; |
shemminger | c595c79 | 2005-11-01 23:03:03 +0000 | [diff] [blame] | 366 | } else if (matches(*argv, "SA") == 0) { |
| 367 | lsa=1; |
| 368 | groups = 0; |
jamal | c9fd974 | 2006-12-07 20:31:14 -0500 | [diff] [blame] | 369 | } else if (matches(*argv, "aevent") == 0) { |
| 370 | laevent=1; |
| 371 | groups = 0; |
shemminger | c595c79 | 2005-11-01 23:03:03 +0000 | [diff] [blame] | 372 | } else if (matches(*argv, "policy") == 0) { |
| 373 | lpolicy=1; |
| 374 | groups = 0; |
Masahide NAKAMURA | c54f31e | 2006-12-05 19:16:05 +0900 | [diff] [blame] | 375 | } else if (matches(*argv, "report") == 0) { |
| 376 | lreport=1; |
| 377 | groups = 0; |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 378 | } else if (matches(*argv, "help") == 0) { |
| 379 | usage(); |
Vadim Kochan | 5bf9f5c | 2015-02-14 19:45:04 +0200 | [diff] [blame] | 380 | } else if (strcmp(*argv, "all")) { |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 381 | fprintf(stderr, "Argument \"%s\" is unknown, try \"ip xfrm monitor help\".\n", *argv); |
| 382 | exit(-1); |
| 383 | } |
| 384 | argc--; argv++; |
| 385 | } |
| 386 | |
| 387 | if (lacquire) |
jamal | 7b82251 | 2006-12-07 20:58:23 -0500 | [diff] [blame] | 388 | groups |= nl_mgrp(XFRMNLGRP_ACQUIRE); |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 389 | if (lexpire) |
jamal | 7b82251 | 2006-12-07 20:58:23 -0500 | [diff] [blame] | 390 | groups |= nl_mgrp(XFRMNLGRP_EXPIRE); |
shemminger | c595c79 | 2005-11-01 23:03:03 +0000 | [diff] [blame] | 391 | if (lsa) |
jamal | 7b82251 | 2006-12-07 20:58:23 -0500 | [diff] [blame] | 392 | groups |= nl_mgrp(XFRMNLGRP_SA); |
shemminger | c595c79 | 2005-11-01 23:03:03 +0000 | [diff] [blame] | 393 | if (lpolicy) |
jamal | 7b82251 | 2006-12-07 20:58:23 -0500 | [diff] [blame] | 394 | groups |= nl_mgrp(XFRMNLGRP_POLICY); |
jamal | c9fd974 | 2006-12-07 20:31:14 -0500 | [diff] [blame] | 395 | if (laevent) |
jamal | 7b82251 | 2006-12-07 20:58:23 -0500 | [diff] [blame] | 396 | groups |= nl_mgrp(XFRMNLGRP_AEVENTS); |
Masahide NAKAMURA | c54f31e | 2006-12-05 19:16:05 +0900 | [diff] [blame] | 397 | if (lreport) |
jamal | 7b82251 | 2006-12-07 20:58:23 -0500 | [diff] [blame] | 398 | groups |= nl_mgrp(XFRMNLGRP_REPORT); |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 399 | |
| 400 | if (file) { |
| 401 | FILE *fp; |
| 402 | fp = fopen(file, "r"); |
| 403 | if (fp == NULL) { |
| 404 | perror("Cannot fopen"); |
| 405 | exit(-1); |
| 406 | } |
| 407 | return rtnl_from_file(fp, xfrm_accept_msg, (void*)stdout); |
| 408 | } |
| 409 | |
shemminger | c595c79 | 2005-11-01 23:03:03 +0000 | [diff] [blame] | 410 | if (rtnl_open_byproto(&rth, groups, NETLINK_XFRM) < 0) |
| 411 | exit(1); |
| 412 | |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 413 | if (rtnl_listen(&rth, xfrm_accept_msg, (void*)stdout) < 0) |
| 414 | exit(2); |
| 415 | |
shemminger | 351efcd | 2005-09-01 19:21:50 +0000 | [diff] [blame] | 416 | return 0; |
linux-ipv6.org!nakam | f9cb3a2 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 417 | } |