]> git.proxmox.com Git - mirror_iproute2.git/blame - ip/ipxfrm.c
cgroup support
[mirror_iproute2.git] / ip / ipxfrm.c
CommitLineData
c7699875 1/* $USAGI: $ */
2
3/*
4 * Copyright (C)2004 USAGI/WIDE Project
ae665a52 5 *
c7699875 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.
ae665a52 10 *
c7699875 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.
ae665a52 15 *
c7699875 16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20/*
21 * based on ip.c, iproute.c
22 */
23/*
24 * Authors:
25 * Masahide NAKAMURA @USAGI
26 */
27
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31#include <sys/types.h>
32#include <sys/socket.h>
33#include <time.h>
34#include <netdb.h>
c7699875 35#include <linux/netlink.h>
36#include <linux/rtnetlink.h>
37#include <linux/xfrm.h>
38
39#include "utils.h"
40#include "xfrm.h"
41
15ac4cdc 42#define STRBUF_SIZE (128)
43#define STRBUF_CAT(buf, str) \
44 do { \
45 int rest = sizeof(buf) - 1 - strlen(buf); \
46 if (rest > 0) { \
47 int len = strlen(str); \
48 if (len > rest) \
49 len = rest; \
50 strncat(buf, str, len); \
51 buf[sizeof(buf) - 1] = '\0'; \
52 } \
53 } while(0);
54
c7699875 55struct xfrm_filter filter;
56
57static void usage(void) __attribute__((noreturn));
58
59static void usage(void)
60{
ae665a52 61 fprintf(stderr,
c7699875 62 "Usage: ip xfrm XFRM_OBJECT { COMMAND | help }\n"
15ac4cdc 63 "where XFRM_OBJECT := { state | policy | monitor }\n");
c7699875 64 exit(-1);
65}
66
eaa34ee3 67/* This is based on utils.c(inet_addr_match) */
68int xfrm_addr_match(xfrm_address_t *x1, xfrm_address_t *x2, int bits)
69{
70 __u32 *a1 = (__u32 *)x1;
71 __u32 *a2 = (__u32 *)x2;
72 int words = bits >> 0x05;
73
74 bits &= 0x1f;
75
76 if (words)
77 if (memcmp(a1, a2, words << 2))
78 return -1;
79
80 if (bits) {
81 __u32 w1, w2;
82 __u32 mask;
83
84 w1 = a1[words];
85 w2 = a2[words];
86
87 mask = htonl((0xffffffff) << (0x20 - bits));
88
89 if ((w1 ^ w2) & mask)
90 return 1;
91 }
92
93 return 0;
94}
95
7ea4f5d3
MN
96int xfrm_xfrmproto_is_ipsec(__u8 proto)
97{
98 return (proto == IPPROTO_ESP ||
99 proto == IPPROTO_AH ||
100 proto == IPPROTO_COMP);
101}
102
103int xfrm_xfrmproto_is_ro(__u8 proto)
104{
105 return (proto == IPPROTO_ROUTING ||
106 proto == IPPROTO_DSTOPTS);
107}
108
7809c616 109struct typeent {
110 const char *t_name;
111 int t_type;
112};
113
29aa4dd7 114static const struct typeent xfrmproto_types[]= {
eaa34ee3 115 { "esp", IPPROTO_ESP }, { "ah", IPPROTO_AH }, { "comp", IPPROTO_COMP },
7ea4f5d3 116 { "route2", IPPROTO_ROUTING }, { "hao", IPPROTO_DSTOPTS },
efe69c1b 117 { "ipsec-any", IPSEC_PROTO_ANY },
eaa34ee3 118 { NULL, -1 }
29aa4dd7 119};
120
121int xfrm_xfrmproto_getbyname(char *name)
122{
123 int i;
124
125 for (i = 0; ; i++) {
126 const struct typeent *t = &xfrmproto_types[i];
127 if (!t->t_name || t->t_type == -1)
128 break;
129
130 if (strcmp(t->t_name, name) == 0)
131 return t->t_type;
132 }
133
134 return -1;
135}
136
137const char *strxf_xfrmproto(__u8 proto)
138{
efe69c1b 139 static char str[16];
29aa4dd7 140 int i;
141
142 for (i = 0; ; i++) {
143 const struct typeent *t = &xfrmproto_types[i];
144 if (!t->t_name || t->t_type == -1)
145 break;
146
147 if (t->t_type == proto)
148 return t->t_name;
149 }
150
efe69c1b
MN
151 sprintf(str, "%u", proto);
152 return str;
29aa4dd7 153}
154
7809c616 155static const struct typeent algo_types[]= {
156 { "enc", XFRMA_ALG_CRYPT }, { "auth", XFRMA_ALG_AUTH },
1758a81f
HX
157 { "comp", XFRMA_ALG_COMP }, { "aead", XFRMA_ALG_AEAD },
158 { NULL, -1 }
7809c616 159};
160
161int xfrm_algotype_getbyname(char *name)
162{
163 int i;
164
165 for (i = 0; ; i++) {
166 const struct typeent *t = &algo_types[i];
167 if (!t->t_name || t->t_type == -1)
168 break;
169
170 if (strcmp(t->t_name, name) == 0)
171 return t->t_type;
172 }
173
174 return -1;
175}
176
177const char *strxf_algotype(int type)
178{
efe69c1b 179 static char str[32];
7809c616 180 int i;
181
182 for (i = 0; ; i++) {
183 const struct typeent *t = &algo_types[i];
184 if (!t->t_name || t->t_type == -1)
185 break;
186
187 if (t->t_type == type)
188 return t->t_name;
189 }
190
efe69c1b
MN
191 sprintf(str, "%d", type);
192 return str;
7809c616 193}
194
eaa34ee3 195const char *strxf_mask8(__u8 mask)
c7699875 196{
197 static char str[16];
eaa34ee3 198 const int sn = sizeof(mask) * 8 - 1;
c7699875 199 __u8 b;
200 int i = 0;
201
202 for (b = (1 << sn); b > 0; b >>= 1)
eaa34ee3 203 str[i++] = ((b & mask) ? '1' : '0');
c7699875 204 str[i] = '\0';
205
206 return str;
207}
208
eaa34ee3 209const char *strxf_mask32(__u32 mask)
210{
211 static char str[16];
212
213 sprintf(str, "%.8x", mask);
214
215 return str;
216}
217
c7699875 218const char *strxf_share(__u8 share)
219{
220 static char str[32];
221
222 switch (share) {
223 case XFRM_SHARE_ANY:
224 strcpy(str, "any");
225 break;
226 case XFRM_SHARE_SESSION:
227 strcpy(str, "session");
228 break;
229 case XFRM_SHARE_USER:
230 strcpy(str, "user");
231 break;
232 case XFRM_SHARE_UNIQUE:
233 strcpy(str, "unique");
234 break;
235 default:
eaa34ee3 236 sprintf(str, "%u", share);
c7699875 237 break;
238 }
239
240 return str;
241}
242
ad273962 243const char *strxf_proto(__u8 proto)
244{
245 static char buf[32];
246 struct protoent *pp;
247 const char *p;
248
249 pp = getprotobynumber(proto);
250 if (pp)
251 p = pp->p_name;
252 else {
eaa34ee3 253 sprintf(buf, "%u", proto);
ad273962 254 p = buf;
255 }
256
257 return p;
258}
259
efe69c1b
MN
260const char *strxf_ptype(__u8 ptype)
261{
262 static char str[16];
263
264 switch (ptype) {
265 case XFRM_POLICY_TYPE_MAIN:
266 strcpy(str, "main");
267 break;
268 case XFRM_POLICY_TYPE_SUB:
269 strcpy(str, "sub");
270 break;
271 default:
272 sprintf(str, "%u", ptype);
273 break;
274 }
275
276 return str;
277}
278
c7699875 279void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id,
eaa34ee3 280 __u8 mode, __u32 reqid, __u16 family, int force_spi,
15ac4cdc 281 FILE *fp, const char *prefix, const char *title)
c7699875 282{
283 char abuf[256];
c7699875 284
15ac4cdc 285 if (title)
9a73e17d 286 fputs(title, fp);
c7699875 287
288 memset(abuf, '\0', sizeof(abuf));
ad273962 289 fprintf(fp, "src %s ", rt_addr_n2a(family, sizeof(*saddr),
290 saddr, abuf, sizeof(abuf)));
c7699875 291 memset(abuf, '\0', sizeof(abuf));
7809c616 292 fprintf(fp, "dst %s", rt_addr_n2a(family, sizeof(id->daddr),
293 &id->daddr, abuf, sizeof(abuf)));
294 fprintf(fp, "%s", _SL_);
c7699875 295
296 if (prefix)
9a73e17d 297 fputs(prefix, fp);
c7699875 298 fprintf(fp, "\t");
299
29aa4dd7 300 fprintf(fp, "proto %s ", strxf_xfrmproto(id->proto));
c7699875 301
eaa34ee3 302 if (show_stats > 0 || force_spi || id->spi) {
303 __u32 spi = ntohl(id->spi);
304 fprintf(fp, "spi 0x%08x", spi);
305 if (show_stats > 0)
306 fprintf(fp, "(%u)", spi);
307 fprintf(fp, " ");
308 }
c7699875 309
ad273962 310 fprintf(fp, "reqid %u", reqid);
311 if (show_stats > 0)
312 fprintf(fp, "(0x%08x)", reqid);
313 fprintf(fp, " ");
c7699875 314
7809c616 315 fprintf(fp, "mode ");
316 switch (mode) {
7ea4f5d3 317 case XFRM_MODE_TRANSPORT:
7809c616 318 fprintf(fp, "transport");
319 break;
7ea4f5d3 320 case XFRM_MODE_TUNNEL:
7809c616 321 fprintf(fp, "tunnel");
322 break;
7ea4f5d3
MN
323 case XFRM_MODE_ROUTEOPTIMIZATION:
324 fprintf(fp, "ro");
325 break;
326 case XFRM_MODE_IN_TRIGGER:
327 fprintf(fp, "in_trigger");
328 break;
329 case XFRM_MODE_BEET:
34e099e2
SH
330 fprintf(fp, "beet");
331 break;
7809c616 332 default:
333 fprintf(fp, "%u", mode);
334 break;
335 }
336 fprintf(fp, "%s", _SL_);
c7699875 337}
338
339static const char *strxf_limit(__u64 limit)
340{
341 static char str[32];
342 if (limit == XFRM_INF)
343 strcpy(str, "(INF)");
344 else
b906243b 345 sprintf(str, "%llu", (unsigned long long) limit);
c7699875 346
347 return str;
348}
349
350void xfrm_stats_print(struct xfrm_stats *s, FILE *fp, const char *prefix)
351{
352 if (prefix)
9a73e17d 353 fputs(prefix, fp);
7809c616 354 fprintf(fp, "stats:");
355 fprintf(fp, "%s", _SL_);
c7699875 356
357 if (prefix)
9a73e17d 358 fputs(prefix, fp);
c7699875 359 fprintf(fp, " ");
eaa34ee3 360 fprintf(fp, "replay-window %u ", s->replay_window);
361 fprintf(fp, "replay %u ", s->replay);
362 fprintf(fp, "failed %u", s->integrity_failed);
7809c616 363 fprintf(fp, "%s", _SL_);
c7699875 364}
365
366static const char *strxf_time(__u64 time)
367{
368 static char str[32];
c7699875 369
7809c616 370 if (time == 0)
371 strcpy(str, "-");
372 else {
373 time_t t;
374 struct tm *tp;
375
ae665a52 376 /* XXX: treat time in the same manner of kernel's
7809c616 377 * net/xfrm/xfrm_{user,state}.c
378 */
c7699875 379 t = (long)time;
380 tp = localtime(&t);
381
44d3eb25 382 strftime(str, sizeof(str), "%Y-%m-%d %T", tp);
c7699875 383 }
384
385 return str;
386}
387
388void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg,
389 struct xfrm_lifetime_cur *cur,
390 FILE *fp, const char *prefix)
391{
392 if (cfg) {
393 if (prefix)
9a73e17d 394 fputs(prefix, fp);
7809c616 395 fprintf(fp, "lifetime config:");
396 fprintf(fp, "%s", _SL_);
c7699875 397
398 if (prefix)
9a73e17d 399 fputs(prefix, fp);
c7699875 400 fprintf(fp, " ");
401 fprintf(fp, "limit: ");
402 fprintf(fp, "soft ");
403 fprintf(fp, strxf_limit(cfg->soft_byte_limit));
404 fprintf(fp, "(bytes), hard ");
405 fprintf(fp, strxf_limit(cfg->hard_byte_limit));
7809c616 406 fprintf(fp, "(bytes)");
407 fprintf(fp, "%s", _SL_);
c7699875 408
409 if (prefix)
9a73e17d 410 fputs(prefix, fp);
c7699875 411 fprintf(fp, " ");
412 fprintf(fp, "limit: ");
413 fprintf(fp, "soft ");
414 fprintf(fp, strxf_limit(cfg->soft_packet_limit));
415 fprintf(fp, "(packets), hard ");
416 fprintf(fp, strxf_limit(cfg->hard_packet_limit));
7809c616 417 fprintf(fp, "(packets)");
418 fprintf(fp, "%s", _SL_);
c7699875 419
420 if (prefix)
9a73e17d 421 fputs(prefix, fp);
c7699875 422 fprintf(fp, " ");
423 fprintf(fp, "expire add: ");
424 fprintf(fp, "soft ");
b906243b 425 fprintf(fp, "%llu", (unsigned long long) cfg->soft_add_expires_seconds);
c7699875 426 fprintf(fp, "(sec), hard ");
b906243b 427 fprintf(fp, "%llu", (unsigned long long) cfg->hard_add_expires_seconds);
7809c616 428 fprintf(fp, "(sec)");
429 fprintf(fp, "%s", _SL_);
c7699875 430
431 if (prefix)
9a73e17d 432 fputs(prefix, fp);
c7699875 433 fprintf(fp, " ");
434 fprintf(fp, "expire use: ");
435 fprintf(fp, "soft ");
b906243b 436 fprintf(fp, "%llu", (unsigned long long) cfg->soft_use_expires_seconds);
c7699875 437 fprintf(fp, "(sec), hard ");
b906243b 438 fprintf(fp, "%llu", (unsigned long long) cfg->hard_use_expires_seconds);
7809c616 439 fprintf(fp, "(sec)");
440 fprintf(fp, "%s", _SL_);
c7699875 441 }
442 if (cur) {
443 if (prefix)
9a73e17d 444 fputs(prefix, fp);
7809c616 445 fprintf(fp, "lifetime current:");
446 fprintf(fp, "%s", _SL_);
c7699875 447
448 if (prefix)
9a73e17d 449 fputs(prefix, fp);
c7699875 450 fprintf(fp, " ");
b906243b 451 fprintf(fp, "%llu(bytes), ", (unsigned long long) cur->bytes);
452 fprintf(fp, "%llu(packets)", (unsigned long long) cur->packets);
7809c616 453 fprintf(fp, "%s", _SL_);
454
c7699875 455 if (prefix)
9a73e17d 456 fputs(prefix, fp);
c7699875 457 fprintf(fp, " ");
458 fprintf(fp, "add %s ", strxf_time(cur->add_time));
459 fprintf(fp, "use %s", strxf_time(cur->use_time));
7809c616 460 fprintf(fp, "%s", _SL_);
c7699875 461 }
462}
463
464void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
465 FILE *fp, const char *prefix)
466{
467 char abuf[256];
468 __u16 f;
469
470 f = sel->family;
471 if (f == AF_UNSPEC)
472 f = family;
473 if (f == AF_UNSPEC)
474 f = preferred_family;
475
476 if (prefix)
9a73e17d 477 fputs(prefix, fp);
c7699875 478
479 memset(abuf, '\0', sizeof(abuf));
eaa34ee3 480 fprintf(fp, "src %s/%u ", rt_addr_n2a(f, sizeof(sel->saddr),
ad273962 481 &sel->saddr, abuf, sizeof(abuf)),
482 sel->prefixlen_s);
c7699875 483
484 memset(abuf, '\0', sizeof(abuf));
eaa34ee3 485 fprintf(fp, "dst %s/%u ", rt_addr_n2a(f, sizeof(sel->daddr),
ad273962 486 &sel->daddr, abuf, sizeof(abuf)),
487 sel->prefixlen_d);
c7699875 488
7809c616 489 if (sel->proto)
490 fprintf(fp, "proto %s ", strxf_proto(sel->proto));
c70b36d2 491 switch (sel->proto) {
492 case IPPROTO_TCP:
493 case IPPROTO_UDP:
494 case IPPROTO_SCTP:
27356a5e 495 case IPPROTO_DCCP:
c70b36d2 496 default: /* XXX */
497 if (sel->sport_mask)
498 fprintf(fp, "sport %u ", ntohs(sel->sport));
499 if (sel->dport_mask)
500 fprintf(fp, "dport %u ", ntohs(sel->dport));
501 break;
502 case IPPROTO_ICMP:
503 case IPPROTO_ICMPV6:
504 /* type/code is stored at sport/dport in selector */
505 if (sel->sport_mask)
506 fprintf(fp, "type %u ", ntohs(sel->sport));
507 if (sel->dport_mask)
508 fprintf(fp, "code %u ", ntohs(sel->dport));
509 break;
0bf0fbc4
MN
510 case IPPROTO_MH:
511 if (sel->sport_mask)
512 fprintf(fp, "type %u ", ntohs(sel->sport));
513 if (sel->dport_mask) {
514 if (show_stats > 0)
515 fprintf(fp, "(dport) 0x%.4x ", sel->dport);
516 }
517 break;
c70b36d2 518 }
c7699875 519
dcb283c3
TG
520 if (sel->ifindex > 0)
521 fprintf(fp, "dev %s ", ll_index_to_name(sel->ifindex));
c7699875 522
ad273962 523 if (show_stats > 0)
524 fprintf(fp, "uid %u", sel->user);
7809c616 525
526 fprintf(fp, "%s", _SL_);
c7699875 527}
528
1758a81f
HX
529static void __xfrm_algo_print(struct xfrm_algo *algo, int type, int len,
530 FILE *fp, const char *prefix, int newline)
c7699875 531{
eaa34ee3 532 int keylen;
c7699875 533 int i;
534
535 if (prefix)
9a73e17d 536 fputs(prefix, fp);
c7699875 537
7809c616 538 fprintf(fp, "%s ", strxf_algotype(type));
eaa34ee3 539
540 if (len < sizeof(*algo)) {
541 fprintf(fp, "(ERROR truncated)");
542 goto fin;
543 }
544 len -= sizeof(*algo);
545
7809c616 546 fprintf(fp, "%s ", algo->alg_name);
c7699875 547
eaa34ee3 548 keylen = algo->alg_key_len / 8;
549 if (len < keylen) {
550 fprintf(fp, "(ERROR truncated)");
551 goto fin;
552 }
553
7809c616 554 fprintf(fp, "0x");
eaa34ee3 555 for (i = 0; i < keylen; i ++)
7809c616 556 fprintf(fp, "%.2x", (unsigned char)algo->alg_key[i]);
c7699875 557
7809c616 558 if (show_stats > 0)
559 fprintf(fp, " (%d bits)", algo->alg_key_len);
560
eaa34ee3 561 fin:
1758a81f
HX
562 if (newline)
563 fprintf(fp, "%s", _SL_);
564}
565
566static inline void xfrm_algo_print(struct xfrm_algo *algo, int type, int len,
567 FILE *fp, const char *prefix)
568{
569 return __xfrm_algo_print(algo, type, len, fp, prefix, 1);
570}
571
572static void xfrm_aead_print(struct xfrm_algo_aead *algo, int len,
573 FILE *fp, const char *prefix)
574{
575 struct {
576 struct xfrm_algo algo;
577 char key[algo->alg_key_len / 8];
578 } base;
579
580 memcpy(base.algo.alg_name, algo->alg_name, sizeof(base.algo.alg_name));
581 base.algo.alg_key_len = algo->alg_key_len;
582 memcpy(base.algo.alg_key, algo->alg_key, algo->alg_key_len / 8);
583
584 __xfrm_algo_print(&base.algo, XFRMA_ALG_AEAD, len, fp, prefix, 0);
585
586 fprintf(fp, " %d", algo->alg_icv_len);
587
7809c616 588 fprintf(fp, "%s", _SL_);
c7699875 589}
590
eaa34ee3 591static void xfrm_tmpl_print(struct xfrm_user_tmpl *tmpls, int len,
c7699875 592 __u16 family, FILE *fp, const char *prefix)
593{
eaa34ee3 594 int ntmpls = len / sizeof(struct xfrm_user_tmpl);
c7699875 595 int i;
596
eaa34ee3 597 if (ntmpls <= 0) {
598 if (prefix)
9a73e17d 599 fputs(prefix, fp);
eaa34ee3 600 fprintf(fp, "(ERROR \"tmpl\" truncated)");
601 fprintf(fp, "%s", _SL_);
602 return;
603 }
604
c7699875 605 for (i = 0; i < ntmpls; i++) {
606 struct xfrm_user_tmpl *tmpl = &tmpls[i];
607
608 if (prefix)
9a73e17d 609 fputs(prefix, fp);
ad273962 610
c7699875 611 xfrm_id_info_print(&tmpl->saddr, &tmpl->id, tmpl->mode,
15ac4cdc 612 tmpl->reqid, family, 0, fp, prefix, "tmpl ");
eaa34ee3 613
614 if (show_stats > 0 || tmpl->optional) {
615 if (prefix)
9a73e17d 616 fputs(prefix, fp);
eaa34ee3 617 fprintf(fp, "\t");
618 switch (tmpl->optional) {
619 case 0:
620 if (show_stats > 0)
621 fprintf(fp, "level required ");
622 break;
623 case 1:
624 fprintf(fp, "level use ");
625 break;
626 default:
627 fprintf(fp, "level %u ", tmpl->optional);
628 break;
629 }
c7699875 630
7809c616 631 if (show_stats > 0)
eaa34ee3 632 fprintf(fp, "share %s ", strxf_share(tmpl->share));
633
634 fprintf(fp, "%s", _SL_);
ad273962 635 }
ad273962 636
637 if (show_stats > 0) {
eaa34ee3 638 if (prefix)
9a73e17d 639 fputs(prefix, fp);
eaa34ee3 640 fprintf(fp, "\t");
641 fprintf(fp, "%s-mask %s ",
7809c616 642 strxf_algotype(XFRMA_ALG_CRYPT),
eaa34ee3 643 strxf_mask32(tmpl->ealgos));
644 fprintf(fp, "%s-mask %s ",
7809c616 645 strxf_algotype(XFRMA_ALG_AUTH),
eaa34ee3 646 strxf_mask32(tmpl->aalgos));
647 fprintf(fp, "%s-mask %s",
7809c616 648 strxf_algotype(XFRMA_ALG_COMP),
eaa34ee3 649 strxf_mask32(tmpl->calgos));
650
651 fprintf(fp, "%s", _SL_);
ad273962 652 }
c7699875 653 }
654}
655
bcf32819 656void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
c7699875 657 FILE *fp, const char *prefix)
658{
bcf32819 659 if (tb[XFRMA_ALG_AUTH]) {
660 struct rtattr *rta = tb[XFRMA_ALG_AUTH];
661 xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
5cf576d9 662 XFRMA_ALG_AUTH, RTA_PAYLOAD(rta), fp, prefix);
bcf32819 663 }
c7699875 664
1758a81f
HX
665 if (tb[XFRMA_ALG_AEAD]) {
666 struct rtattr *rta = tb[XFRMA_ALG_AEAD];
667 xfrm_aead_print((struct xfrm_algo_aead *)RTA_DATA(rta),
668 RTA_PAYLOAD(rta), fp, prefix);
669 }
670
bcf32819 671 if (tb[XFRMA_ALG_CRYPT]) {
672 struct rtattr *rta = tb[XFRMA_ALG_CRYPT];
673 xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
5cf576d9 674 XFRMA_ALG_CRYPT, RTA_PAYLOAD(rta), fp, prefix);
bcf32819 675 }
eaa34ee3 676
bcf32819 677 if (tb[XFRMA_ALG_COMP]) {
678 struct rtattr *rta = tb[XFRMA_ALG_COMP];
679 xfrm_algo_print((struct xfrm_algo *) RTA_DATA(rta),
5cf576d9 680 XFRMA_ALG_COMP, RTA_PAYLOAD(rta), fp, prefix);
bcf32819 681 }
eaa34ee3 682
bcf32819 683 if (tb[XFRMA_ENCAP]) {
684 struct xfrm_encap_tmpl *e;
685 char abuf[256];
eaa34ee3 686
bcf32819 687 if (prefix)
9a73e17d 688 fputs(prefix, fp);
bcf32819 689 fprintf(fp, "encap ");
eaa34ee3 690
bcf32819 691 if (RTA_PAYLOAD(tb[XFRMA_ENCAP]) < sizeof(*e)) {
692 fprintf(fp, "(ERROR truncated)");
7809c616 693 fprintf(fp, "%s", _SL_);
bcf32819 694 return;
c7699875 695 }
bcf32819 696 e = (struct xfrm_encap_tmpl *) RTA_DATA(tb[XFRMA_ENCAP]);
697
5cf576d9
SH
698 fprintf(fp, "type ");
699 switch (e->encap_type) {
700 case 1:
701 fprintf(fp, "espinudp-nonike ");
702 break;
703 case 2:
704 fprintf(fp, "espinudp ");
705 break;
706 default:
707 fprintf(fp, "%u ", e->encap_type);
708 break;
709 }
bcf32819 710 fprintf(fp, "sport %u ", ntohs(e->encap_sport));
711 fprintf(fp, "dport %u ", ntohs(e->encap_dport));
712
713 memset(abuf, '\0', sizeof(abuf));
714 fprintf(fp, "addr %s",
715 rt_addr_n2a(family, sizeof(e->encap_oa),
716 &e->encap_oa, abuf, sizeof(abuf)));
717 fprintf(fp, "%s", _SL_);
718 }
719
720 if (tb[XFRMA_TMPL]) {
721 struct rtattr *rta = tb[XFRMA_TMPL];
722 xfrm_tmpl_print((struct xfrm_user_tmpl *) RTA_DATA(rta),
5cf576d9 723 RTA_PAYLOAD(rta), family, fp, prefix);
c7699875 724 }
7ea4f5d3
MN
725
726 if (tb[XFRMA_COADDR]) {
727 char abuf[256];
728 xfrm_address_t *coa;
729
730 if (prefix)
9a73e17d 731 fputs(prefix, fp);
7ea4f5d3
MN
732 fprintf(fp, "coa ");
733
734 coa = (xfrm_address_t *)RTA_DATA(tb[XFRMA_COADDR]);
735
736 if (RTA_PAYLOAD(tb[XFRMA_COADDR]) < sizeof(*coa)) {
737 fprintf(fp, "(ERROR truncated)");
738 fprintf(fp, "%s", _SL_);
739 return;
740 }
741
742 memset(abuf, '\0', sizeof(abuf));
743 fprintf(fp, "%s",
ae665a52 744 rt_addr_n2a(family, sizeof(*coa), coa,
7ea4f5d3
MN
745 abuf, sizeof(abuf)));
746 fprintf(fp, "%s", _SL_);
747 }
748
749 if (tb[XFRMA_LASTUSED]) {
750 __u64 lastused;
751
752 if (prefix)
9a73e17d 753 fputs(prefix, fp);
7ea4f5d3
MN
754 fprintf(fp, "lastused ");
755
756 if (RTA_PAYLOAD(tb[XFRMA_LASTUSED]) < sizeof(lastused)) {
757 fprintf(fp, "(ERROR truncated)");
758 fprintf(fp, "%s", _SL_);
759 return;
760 }
761
762 lastused = *(__u64 *)RTA_DATA(tb[XFRMA_LASTUSED]);
763
764 fprintf(fp, "%s", strxf_time(lastused));
765 fprintf(fp, "%s", _SL_);
766 }
c7699875 767}
768
15ac4cdc 769static int xfrm_selector_iszero(struct xfrm_selector *s)
770{
771 struct xfrm_selector s0;
772
773 memset(&s0, 0, sizeof(s0));
774
775 return (memcmp(&s0, s, sizeof(s0)) == 0);
776}
777
778void xfrm_state_info_print(struct xfrm_usersa_info *xsinfo,
779 struct rtattr *tb[], FILE *fp, const char *prefix,
780 const char *title)
781{
782 char buf[STRBUF_SIZE];
7ea4f5d3 783 int force_spi = xfrm_xfrmproto_is_ipsec(xsinfo->id.proto);
15ac4cdc 784
785 memset(buf, '\0', sizeof(buf));
786
787 xfrm_id_info_print(&xsinfo->saddr, &xsinfo->id, xsinfo->mode,
7ea4f5d3
MN
788 xsinfo->reqid, xsinfo->family, force_spi, fp,
789 prefix, title);
15ac4cdc 790
791 if (prefix)
792 STRBUF_CAT(buf, prefix);
793 STRBUF_CAT(buf, "\t");
794
9a73e17d 795 fputs(buf, fp);
15ac4cdc 796 fprintf(fp, "replay-window %u ", xsinfo->replay_window);
797 if (show_stats > 0)
798 fprintf(fp, "seq 0x%08u ", xsinfo->seq);
799 if (show_stats > 0 || xsinfo->flags) {
800 __u8 flags = xsinfo->flags;
801
802 fprintf(fp, "flag ");
803 XFRM_FLAG_PRINT(fp, flags, XFRM_STATE_NOECN, "noecn");
804 XFRM_FLAG_PRINT(fp, flags, XFRM_STATE_DECAP_DSCP, "decap-dscp");
c1fa2253 805 XFRM_FLAG_PRINT(fp, flags, XFRM_STATE_NOPMTUDISC, "nopmtudisc");
7ea4f5d3 806 XFRM_FLAG_PRINT(fp, flags, XFRM_STATE_WILDRECV, "wildrecv");
15ac4cdc 807 if (flags)
808 fprintf(fp, "%x", flags);
15ac4cdc 809 }
c1fa2253
MN
810 if (show_stats > 0)
811 fprintf(fp, " (0x%s)", strxf_mask8(xsinfo->flags));
15ac4cdc 812 fprintf(fp, "%s", _SL_);
813
814 xfrm_xfrma_print(tb, xsinfo->family, fp, buf);
815
816 if (!xfrm_selector_iszero(&xsinfo->sel)) {
817 char sbuf[STRBUF_SIZE];
818
819 memcpy(sbuf, buf, sizeof(sbuf));
820 STRBUF_CAT(sbuf, "sel ");
821
822 xfrm_selector_print(&xsinfo->sel, xsinfo->family, fp, sbuf);
823 }
824
825 if (show_stats > 0) {
826 xfrm_lifetime_print(&xsinfo->lft, &xsinfo->curlft, fp, buf);
827 xfrm_stats_print(&xsinfo->stats, fp, buf);
828 }
829}
830
831void xfrm_policy_info_print(struct xfrm_userpolicy_info *xpinfo,
832 struct rtattr *tb[], FILE *fp, const char *prefix,
833 const char *title)
834{
835 char buf[STRBUF_SIZE];
836
837 memset(buf, '\0', sizeof(buf));
838
839 xfrm_selector_print(&xpinfo->sel, preferred_family, fp, title);
840
841 if (prefix)
842 STRBUF_CAT(buf, prefix);
843 STRBUF_CAT(buf, "\t");
844
9a73e17d 845 fputs(buf, fp);
15ac4cdc 846 fprintf(fp, "dir ");
847 switch (xpinfo->dir) {
848 case XFRM_POLICY_IN:
849 fprintf(fp, "in");
850 break;
851 case XFRM_POLICY_OUT:
852 fprintf(fp, "out");
853 break;
854 case XFRM_POLICY_FWD:
855 fprintf(fp, "fwd");
856 break;
857 default:
858 fprintf(fp, "%u", xpinfo->dir);
859 break;
860 }
861 fprintf(fp, " ");
862
863 switch (xpinfo->action) {
864 case XFRM_POLICY_ALLOW:
865 if (show_stats > 0)
866 fprintf(fp, "action allow ");
867 break;
868 case XFRM_POLICY_BLOCK:
869 fprintf(fp, "action block ");
870 break;
871 default:
872 fprintf(fp, "action %u ", xpinfo->action);
873 break;
874 }
875
876 if (show_stats)
877 fprintf(fp, "index %u ", xpinfo->index);
878 fprintf(fp, "priority %u ", xpinfo->priority);
972938e9 879
972938e9
MN
880 if (tb[XFRMA_POLICY_TYPE]) {
881 struct xfrm_userpolicy_type *upt;
882
efe69c1b
MN
883 fprintf(fp, "ptype ");
884
972938e9
MN
885 if (RTA_PAYLOAD(tb[XFRMA_POLICY_TYPE]) < sizeof(*upt))
886 fprintf(fp, "(ERROR truncated)");
887
888 upt = (struct xfrm_userpolicy_type *)RTA_DATA(tb[XFRMA_POLICY_TYPE]);
efe69c1b 889 fprintf(fp, "%s ", strxf_ptype(upt->type));
972938e9
MN
890 }
891
c1fa2253 892 if (show_stats > 0)
15ac4cdc 893 fprintf(fp, "share %s ", strxf_share(xpinfo->share));
c1fa2253
MN
894
895 if (show_stats > 0 || xpinfo->flags) {
896 __u8 flags = xpinfo->flags;
897
898 fprintf(fp, "flag ");
899 XFRM_FLAG_PRINT(fp, flags, XFRM_POLICY_LOCALOK, "localok");
900 if (flags)
901 fprintf(fp, "%x", flags);
15ac4cdc 902 }
c1fa2253
MN
903 if (show_stats > 0)
904 fprintf(fp, " (0x%s)", strxf_mask8(xpinfo->flags));
15ac4cdc 905 fprintf(fp, "%s", _SL_);
906
907 if (show_stats > 0)
908 xfrm_lifetime_print(&xpinfo->lft, &xpinfo->curlft, fp, buf);
909
910 xfrm_xfrma_print(tb, xpinfo->sel.family, fp, buf);
911}
912
c7699875 913int xfrm_id_parse(xfrm_address_t *saddr, struct xfrm_id *id, __u16 *family,
7809c616 914 int loose, int *argcp, char ***argvp)
c7699875 915{
916 int argc = *argcp;
917 char **argv = *argvp;
918 inet_prefix dst;
919 inet_prefix src;
c7699875 920
921 memset(&dst, 0, sizeof(dst));
922 memset(&src, 0, sizeof(src));
923
924 while (1) {
925 if (strcmp(*argv, "src") == 0) {
926 NEXT_ARG();
927
928 get_prefix(&src, *argv, preferred_family);
929 if (src.family == AF_UNSPEC)
eaa34ee3 930 invarg("\"src\" address family is AF_UNSPEC", *argv);
c7699875 931 if (family)
932 *family = src.family;
933
934 memcpy(saddr, &src.data, sizeof(*saddr));
935
936 filter.id_src_mask = src.bitlen;
937
938 } else if (strcmp(*argv, "dst") == 0) {
939 NEXT_ARG();
940
941 get_prefix(&dst, *argv, preferred_family);
942 if (dst.family == AF_UNSPEC)
eaa34ee3 943 invarg("\"dst\" address family is AF_UNSPEC", *argv);
c7699875 944 if (family)
945 *family = dst.family;
946
947 memcpy(&id->daddr, &dst.data, sizeof(id->daddr));
948
949 filter.id_dst_mask = dst.bitlen;
950
951 } else if (strcmp(*argv, "proto") == 0) {
29aa4dd7 952 int ret;
c7699875 953
954 NEXT_ARG();
955
29aa4dd7 956 ret = xfrm_xfrmproto_getbyname(*argv);
957 if (ret < 0)
958 invarg("\"XFRM_PROTO\" is invalid", *argv);
c7699875 959
29aa4dd7 960 id->proto = (__u8)ret;
c7699875 961
962 filter.id_proto_mask = XFRM_FILTER_MASK_FULL;
963
964 } else if (strcmp(*argv, "spi") == 0) {
965 __u32 spi;
966
967 NEXT_ARG();
968 if (get_u32(&spi, *argv, 0))
969 invarg("\"SPI\" is invalid", *argv);
970
971 spi = htonl(spi);
972 id->spi = spi;
973
974 filter.id_spi_mask = XFRM_FILTER_MASK_FULL;
975
976 } else {
977 PREV_ARG(); /* back track */
978 break;
979 }
980
981 if (!NEXT_ARG_OK())
982 break;
983 NEXT_ARG();
984 }
985
986 if (src.family && dst.family && (src.family != dst.family))
eaa34ee3 987 invarg("the same address family is required between \"src\" and \"dst\"", *argv);
c7699875 988
29aa4dd7 989 if (loose == 0 && id->proto == 0)
990 missarg("XFRM_PROTO");
c7699875 991 if (argc == *argcp)
992 missarg("ID");
993
994 *argcp = argc;
995 *argvp = argv;
996
997 return 0;
998}
999
1000int xfrm_mode_parse(__u8 *mode, int *argcp, char ***argvp)
1001{
1002 int argc = *argcp;
1003 char **argv = *argvp;
1004
1005 if (matches(*argv, "transport") == 0)
7ea4f5d3 1006 *mode = XFRM_MODE_TRANSPORT;
c7699875 1007 else if (matches(*argv, "tunnel") == 0)
7ea4f5d3
MN
1008 *mode = XFRM_MODE_TUNNEL;
1009 else if (matches(*argv, "ro") == 0)
1010 *mode = XFRM_MODE_ROUTEOPTIMIZATION;
1011 else if (matches(*argv, "in_trigger") == 0)
1012 *mode = XFRM_MODE_IN_TRIGGER;
34e099e2 1013 else if (matches(*argv, "beet") == 0)
7ea4f5d3 1014 *mode = XFRM_MODE_BEET;
c7699875 1015 else
1016 invarg("\"MODE\" is invalid", *argv);
1017
1018 *argcp = argc;
1019 *argvp = argv;
1020
1021 return 0;
1022}
1023
5cf576d9
SH
1024int xfrm_encap_type_parse(__u16 *type, int *argcp, char ***argvp)
1025{
1026 int argc = *argcp;
1027 char **argv = *argvp;
1028
1029 if (strcmp(*argv, "espinudp-nonike") == 0)
1030 *type = 1;
1031 else if (strcmp(*argv, "espinudp") == 0)
1032 *type = 2;
1033 else
1034 invarg("\"ENCAP-TYPE\" is invalid", *argv);
1035
1036 *argcp = argc;
1037 *argvp = argv;
1038
1039 return 0;
1040}
1041
c7699875 1042/* NOTE: reqid is used by host-byte order */
1043int xfrm_reqid_parse(__u32 *reqid, int *argcp, char ***argvp)
1044{
1045 int argc = *argcp;
1046 char **argv = *argvp;
1047
1048 if (get_u32(reqid, *argv, 0))
1049 invarg("\"REQID\" is invalid", *argv);
1050
1051 *argcp = argc;
1052 *argvp = argv;
1053
1054 return 0;
1055}
1056
1057static int xfrm_selector_upspec_parse(struct xfrm_selector *sel,
1058 int *argcp, char ***argvp)
1059{
1060 int argc = *argcp;
1061 char **argv = *argvp;
c70b36d2 1062 char *sportp = NULL;
1063 char *dportp = NULL;
1064 char *typep = NULL;
1065 char *codep = NULL;
c7699875 1066
1067 while (1) {
1068 if (strcmp(*argv, "proto") == 0) {
7809c616 1069 __u8 upspec;
1070
c7699875 1071 NEXT_ARG();
1072
1073 if (strcmp(*argv, "any") == 0)
1074 upspec = 0;
1075 else {
1076 struct protoent *pp;
1077 pp = getprotobyname(*argv);
1078 if (pp)
1079 upspec = pp->p_proto;
1080 else {
1081 if (get_u8(&upspec, *argv, 0))
7809c616 1082 invarg("\"PROTO\" is invalid", *argv);
c7699875 1083 }
1084 }
1085 sel->proto = upspec;
1086
1087 filter.upspec_proto_mask = XFRM_FILTER_MASK_FULL;
1088
1089 } else if (strcmp(*argv, "sport") == 0) {
c70b36d2 1090 sportp = *argv;
1091
c7699875 1092 NEXT_ARG();
1093
1094 if (get_u16(&sel->sport, *argv, 0))
1095 invarg("\"PORT\" is invalid", *argv);
1096 sel->sport = htons(sel->sport);
1097 if (sel->sport)
1098 sel->sport_mask = ~((__u16)0);
1099
1100 filter.upspec_sport_mask = XFRM_FILTER_MASK_FULL;
1101
1102 } else if (strcmp(*argv, "dport") == 0) {
c70b36d2 1103 dportp = *argv;
1104
c7699875 1105 NEXT_ARG();
1106
1107 if (get_u16(&sel->dport, *argv, 0))
1108 invarg("\"PORT\" is invalid", *argv);
1109 sel->dport = htons(sel->dport);
1110 if (sel->dport)
1111 sel->dport_mask = ~((__u16)0);
1112
1113 filter.upspec_dport_mask = XFRM_FILTER_MASK_FULL;
1114
c70b36d2 1115 } else if (strcmp(*argv, "type") == 0) {
1116 typep = *argv;
1117
1118 NEXT_ARG();
1119
1120 if (get_u16(&sel->sport, *argv, 0) ||
1121 (sel->sport & ~((__u16)0xff)))
1122 invarg("\"type\" value is invalid", *argv);
1123 sel->sport = htons(sel->sport);
1124 sel->sport_mask = ~((__u16)0);
1125
1126 filter.upspec_sport_mask = XFRM_FILTER_MASK_FULL;
1127
1128
1129 } else if (strcmp(*argv, "code") == 0) {
1130 codep = *argv;
1131
1132 NEXT_ARG();
1133
1134 if (get_u16(&sel->dport, *argv, 0) ||
1135 (sel->dport & ~((__u16)0xff)))
1136 invarg("\"code\" value is invalid", *argv);
1137 sel->dport = htons(sel->dport);
1138 sel->dport_mask = ~((__u16)0);
1139
1140 filter.upspec_dport_mask = XFRM_FILTER_MASK_FULL;
1141
c7699875 1142 } else {
1143 PREV_ARG(); /* back track */
1144 break;
1145 }
1146
1147 if (!NEXT_ARG_OK())
1148 break;
1149 NEXT_ARG();
1150 }
1151 if (argc == *argcp)
1152 missarg("UPSPEC");
c70b36d2 1153 if (sportp || dportp) {
1154 switch (sel->proto) {
1155 case IPPROTO_TCP:
1156 case IPPROTO_UDP:
1157 case IPPROTO_SCTP:
27356a5e 1158 case IPPROTO_DCCP:
c70b36d2 1159 break;
1160 default:
1161 fprintf(stderr, "\"sport\" and \"dport\" are invalid with proto=%s\n", strxf_proto(sel->proto));
1162 exit(1);
1163 }
1164 }
1165 if (typep || codep) {
1166 switch (sel->proto) {
1167 case IPPROTO_ICMP:
1168 case IPPROTO_ICMPV6:
0bf0fbc4 1169 case IPPROTO_MH:
c70b36d2 1170 break;
1171 default:
1172 fprintf(stderr, "\"type\" and \"code\" are invalid with proto=%s\n", strxf_proto(sel->proto));
1173 exit(1);
1174 }
1175 }
c7699875 1176
1177 *argcp = argc;
1178 *argvp = argv;
1179
1180 return 0;
1181}
1182
1183int xfrm_selector_parse(struct xfrm_selector *sel, int *argcp, char ***argvp)
1184{
1185 int argc = *argcp;
1186 char **argv = *argvp;
1187 inet_prefix dst;
1188 inet_prefix src;
7809c616 1189 char *upspecp = NULL;
c7699875 1190
1191 memset(&dst, 0, sizeof(dst));
1192 memset(&src, 0, sizeof(src));
1193
1194 while (1) {
1195 if (strcmp(*argv, "src") == 0) {
1196 NEXT_ARG();
1197
1198 get_prefix(&src, *argv, preferred_family);
1199 if (src.family == AF_UNSPEC)
eaa34ee3 1200 invarg("\"src\" address family is AF_UNSPEC", *argv);
c7699875 1201 sel->family = src.family;
1202
1203 memcpy(&sel->saddr, &src.data, sizeof(sel->saddr));
1204 sel->prefixlen_s = src.bitlen;
1205
1206 filter.sel_src_mask = src.bitlen;
1207
1208 } else if (strcmp(*argv, "dst") == 0) {
1209 NEXT_ARG();
1210
1211 get_prefix(&dst, *argv, preferred_family);
1212 if (dst.family == AF_UNSPEC)
eaa34ee3 1213 invarg("\"dst\" address family is AF_UNSPEC", *argv);
c7699875 1214 sel->family = dst.family;
1215
1216 memcpy(&sel->daddr, &dst.data, sizeof(sel->daddr));
1217 sel->prefixlen_d = dst.bitlen;
1218
1219 filter.sel_dst_mask = dst.bitlen;
1220
c7699875 1221 } else if (strcmp(*argv, "dev") == 0) {
1222 int ifindex;
1223
1224 NEXT_ARG();
1225
1226 if (strcmp(*argv, "none") == 0)
1227 ifindex = 0;
1228 else {
dcb283c3 1229 ifindex = ll_name_to_index(*argv);
c7699875 1230 if (ifindex <= 0)
1231 invarg("\"DEV\" is invalid", *argv);
1232 }
1233 sel->ifindex = ifindex;
1234
1235 filter.sel_dev_mask = XFRM_FILTER_MASK_FULL;
1236
1237 } else {
7809c616 1238 if (upspecp) {
1239 PREV_ARG(); /* back track */
1240 break;
1241 } else {
1242 upspecp = *argv;
1243 xfrm_selector_upspec_parse(sel, &argc, &argv);
1244 }
c7699875 1245 }
1246
1247 if (!NEXT_ARG_OK())
1248 break;
1249
1250 NEXT_ARG();
1251 }
1252
1253 if (src.family && dst.family && (src.family != dst.family))
eaa34ee3 1254 invarg("the same address family is required between \"src\" and \"dst\"", *argv);
c7699875 1255
1256 if (argc == *argcp)
1257 missarg("SELECTOR");
1258
1259 *argcp = argc;
1260 *argvp = argv;
1261
1262 return 0;
1263}
1264
1265int xfrm_lifetime_cfg_parse(struct xfrm_lifetime_cfg *lft,
1266 int *argcp, char ***argvp)
1267{
1268 int argc = *argcp;
1269 char **argv = *argvp;
1270 int ret;
1271
1272 if (strcmp(*argv, "time-soft") == 0) {
1273 NEXT_ARG();
1274 ret = get_u64(&lft->soft_add_expires_seconds, *argv, 0);
1275 if (ret)
1276 invarg("\"time-soft\" value is invalid", *argv);
1277 } else if (strcmp(*argv, "time-hard") == 0) {
1278 NEXT_ARG();
1279 ret = get_u64(&lft->hard_add_expires_seconds, *argv, 0);
1280 if (ret)
1281 invarg("\"time-hard\" value is invalid", *argv);
1282 } else if (strcmp(*argv, "time-use-soft") == 0) {
1283 NEXT_ARG();
1284 ret = get_u64(&lft->soft_use_expires_seconds, *argv, 0);
1285 if (ret)
1286 invarg("\"time-use-soft\" value is invalid", *argv);
1287 } else if (strcmp(*argv, "time-use-hard") == 0) {
1288 NEXT_ARG();
1289 ret = get_u64(&lft->hard_use_expires_seconds, *argv, 0);
1290 if (ret)
1291 invarg("\"time-use-hard\" value is invalid", *argv);
1292 } else if (strcmp(*argv, "byte-soft") == 0) {
1293 NEXT_ARG();
1294 ret = get_u64(&lft->soft_byte_limit, *argv, 0);
1295 if (ret)
1296 invarg("\"byte-soft\" value is invalid", *argv);
1297 } else if (strcmp(*argv, "byte-hard") == 0) {
1298 NEXT_ARG();
1299 ret = get_u64(&lft->hard_byte_limit, *argv, 0);
1300 if (ret)
1301 invarg("\"byte-hard\" value is invalid", *argv);
1302 } else if (strcmp(*argv, "packet-soft") == 0) {
1303 NEXT_ARG();
1304 ret = get_u64(&lft->soft_packet_limit, *argv, 0);
1305 if (ret)
1306 invarg("\"packet-soft\" value is invalid", *argv);
1307 } else if (strcmp(*argv, "packet-hard") == 0) {
1308 NEXT_ARG();
1309 ret = get_u64(&lft->hard_packet_limit, *argv, 0);
1310 if (ret)
1311 invarg("\"packet-hard\" value is invalid", *argv);
1312 } else
1313 invarg("\"LIMIT\" is invalid", *argv);
1314
1315 *argcp = argc;
1316 *argvp = argv;
1317
1318 return 0;
1319}
1320
1321int do_xfrm(int argc, char **argv)
1322{
1323 memset(&filter, 0, sizeof(filter));
1324
1325 if (argc < 1)
1326 usage();
1327
ad273962 1328 if (matches(*argv, "state") == 0 ||
15ac4cdc 1329 matches(*argv, "sa") == 0)
c7699875 1330 return do_xfrm_state(argc-1, argv+1);
15ac4cdc 1331 else if (matches(*argv, "policy") == 0)
c7699875 1332 return do_xfrm_policy(argc-1, argv+1);
15ac4cdc 1333 else if (matches(*argv, "monitor") == 0)
1334 return do_xfrm_monitor(argc-1, argv+1);
ad273962 1335 else if (matches(*argv, "help") == 0) {
c7699875 1336 usage();
1337 fprintf(stderr, "xfrm Object \"%s\" is unknown.\n", *argv);
1338 exit(-1);
1339 }
1340 usage();
1341}