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