4 * Copyright (C)2004 USAGI/WIDE Project
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.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses>.
24 * Masahide NAKAMURA @USAGI
31 #include <bsd/string.h>
36 #include "ip_common.h"
38 /* #define NLMSG_DELETEALL_BUF_SIZE (4096-512) */
39 #define NLMSG_DELETEALL_BUF_SIZE 8192
42 * Receiving buffer defines:
44 * data = struct xfrm_usersa_info
47 * ... (max count of rtattr is XFRM_MAX+1
49 * each rtattr data = struct xfrm_algo(dynamic size) or xfrm_address_t
51 #define NLMSG_BUF_SIZE 4096
52 #define RTA_BUF_SIZE 2048
53 #define XFRM_ALGO_KEY_BUF_SIZE 512
54 #define CTX_BUF_SIZE 256
56 static void usage(void) __attribute__((noreturn
));
58 static void usage(void)
60 fprintf(stderr
, "Usage: ip xfrm state { add | update } ID [ ALGO-LIST ] [ mode MODE ]\n");
61 fprintf(stderr
, " [ mark MARK [ mask MASK ] ] [ reqid REQID ] [ seq SEQ ]\n");
62 fprintf(stderr
, " [ replay-window SIZE ] [ replay-seq SEQ ] [ replay-oseq SEQ ]\n");
63 fprintf(stderr
, " [ replay-seq-hi SEQ ] [ replay-oseq-hi SEQ ]\n");
64 fprintf(stderr
, " [ flag FLAG-LIST ] [ sel SELECTOR ] [ LIMIT-LIST ] [ encap ENCAP ]\n");
65 fprintf(stderr
, " [ coa ADDR[/PLEN] ] [ ctx CTX ] [ extra-flag EXTRA-FLAG-LIST ]\n");
66 fprintf(stderr
, " [ offload [dev DEV] dir DIR ]\n");
67 fprintf(stderr
, " [ output-mark OUTPUT-MARK ]\n");
68 fprintf(stderr
, "Usage: ip xfrm state allocspi ID [ mode MODE ] [ mark MARK [ mask MASK ] ]\n");
69 fprintf(stderr
, " [ reqid REQID ] [ seq SEQ ] [ min SPI max SPI ]\n");
70 fprintf(stderr
, "Usage: ip xfrm state { delete | get } ID [ mark MARK [ mask MASK ] ]\n");
71 fprintf(stderr
, "Usage: ip xfrm state { deleteall | list } [ ID ] [ mode MODE ] [ reqid REQID ]\n");
72 fprintf(stderr
, " [ flag FLAG-LIST ]\n");
73 fprintf(stderr
, "Usage: ip xfrm state flush [ proto XFRM-PROTO ]\n");
74 fprintf(stderr
, "Usage: ip xfrm state count\n");
75 fprintf(stderr
, "ID := [ src ADDR ] [ dst ADDR ] [ proto XFRM-PROTO ] [ spi SPI ]\n");
76 fprintf(stderr
, "XFRM-PROTO := ");
77 fprintf(stderr
, "%s | ", strxf_xfrmproto(IPPROTO_ESP
));
78 fprintf(stderr
, "%s | ", strxf_xfrmproto(IPPROTO_AH
));
79 fprintf(stderr
, "%s | ", strxf_xfrmproto(IPPROTO_COMP
));
80 fprintf(stderr
, "%s | ", strxf_xfrmproto(IPPROTO_ROUTING
));
81 fprintf(stderr
, "%s\n", strxf_xfrmproto(IPPROTO_DSTOPTS
));
82 fprintf(stderr
, "ALGO-LIST := [ ALGO-LIST ] ALGO\n");
83 fprintf(stderr
, "ALGO := { ");
84 fprintf(stderr
, "%s | ", strxf_algotype(XFRMA_ALG_CRYPT
));
85 fprintf(stderr
, "%s", strxf_algotype(XFRMA_ALG_AUTH
));
86 fprintf(stderr
, " } ALGO-NAME ALGO-KEYMAT |\n");
87 fprintf(stderr
, " %s", strxf_algotype(XFRMA_ALG_AUTH_TRUNC
));
88 fprintf(stderr
, " ALGO-NAME ALGO-KEYMAT ALGO-TRUNC-LEN |\n");
89 fprintf(stderr
, " %s", strxf_algotype(XFRMA_ALG_AEAD
));
90 fprintf(stderr
, " ALGO-NAME ALGO-KEYMAT ALGO-ICV-LEN |\n");
91 fprintf(stderr
, " %s", strxf_algotype(XFRMA_ALG_COMP
));
92 fprintf(stderr
, " ALGO-NAME\n");
93 fprintf(stderr
, "MODE := transport | tunnel | beet | ro | in_trigger\n");
94 fprintf(stderr
, "FLAG-LIST := [ FLAG-LIST ] FLAG\n");
95 fprintf(stderr
, "FLAG := noecn | decap-dscp | nopmtudisc | wildrecv | icmp | af-unspec | align4 | esn\n");
96 fprintf(stderr
, "EXTRA-FLAG-LIST := [ EXTRA-FLAG-LIST ] EXTRA-FLAG\n");
97 fprintf(stderr
, "EXTRA-FLAG := dont-encap-dscp\n");
98 fprintf(stderr
, "SELECTOR := [ src ADDR[/PLEN] ] [ dst ADDR[/PLEN] ] [ dev DEV ] [ UPSPEC ]\n");
99 fprintf(stderr
, "UPSPEC := proto { { ");
100 fprintf(stderr
, "%s | ", strxf_proto(IPPROTO_TCP
));
101 fprintf(stderr
, "%s | ", strxf_proto(IPPROTO_UDP
));
102 fprintf(stderr
, "%s | ", strxf_proto(IPPROTO_SCTP
));
103 fprintf(stderr
, "%s", strxf_proto(IPPROTO_DCCP
));
104 fprintf(stderr
, " } [ sport PORT ] [ dport PORT ] |\n");
105 fprintf(stderr
, " { ");
106 fprintf(stderr
, "%s | ", strxf_proto(IPPROTO_ICMP
));
107 fprintf(stderr
, "%s | ", strxf_proto(IPPROTO_ICMPV6
));
108 fprintf(stderr
, "%s", strxf_proto(IPPROTO_MH
));
109 fprintf(stderr
, " } [ type NUMBER ] [ code NUMBER ] |\n");
110 fprintf(stderr
, " %s", strxf_proto(IPPROTO_GRE
));
111 fprintf(stderr
, " [ key { DOTTED-QUAD | NUMBER } ] | PROTO }\n");
112 fprintf(stderr
, "LIMIT-LIST := [ LIMIT-LIST ] limit LIMIT\n");
113 fprintf(stderr
, "LIMIT := { time-soft | time-hard | time-use-soft | time-use-hard } SECONDS |\n");
114 fprintf(stderr
, " { byte-soft | byte-hard } SIZE | { packet-soft | packet-hard } COUNT\n");
115 fprintf(stderr
, "ENCAP := { espinudp | espinudp-nonike } SPORT DPORT OADDR\n");
116 fprintf(stderr
, "DIR := in | out\n");
121 static int xfrm_algo_parse(struct xfrm_algo
*alg
, enum xfrm_attr_type_t type
,
122 char *name
, char *key
, char *buf
, int max
)
125 int slen
= strlen(key
);
128 /* XXX: verifying both name and key is required! */
129 fprintf(stderr
, "warning: ALGO-NAME/ALGO-KEYMAT values will be sent to the kernel promiscuously! (verifying them isn't implemented yet)\n");
132 strlcpy(alg
->alg_name
, name
, sizeof(alg
->alg_name
));
134 if (slen
> 2 && strncmp(key
, "0x", 2) == 0) {
135 /* split two chars "0x" from the top */
141 /* Converting hexadecimal numbered string into real key;
142 * Convert each two chars into one char(value). If number
143 * of the length is odd, add zero on the top for rounding.
146 /* calculate length of the converted values(real key) */
147 len
= (plen
+ 1) / 2;
149 invarg("ALGO-KEYMAT value makes buffer overflow\n", key
);
151 for (i
= -(plen
% 2), j
= 0; j
< len
; i
+= 2, j
++) {
155 vbuf
[0] = i
>= 0 ? p
[i
] : '0';
159 if (get_u8(&val
, vbuf
, 16))
160 invarg("ALGO-KEYMAT value is invalid", key
);
168 invarg("ALGO-KEYMAT value makes buffer overflow\n", key
);
170 memcpy(buf
, key
, len
);
174 alg
->alg_key_len
= len
* 8;
179 static int xfrm_seq_parse(__u32
*seq
, int *argcp
, char ***argvp
)
182 char **argv
= *argvp
;
184 if (get_be32(seq
, *argv
, 0))
185 invarg("SEQ value is invalid", *argv
);
193 static int xfrm_state_flag_parse(__u8
*flags
, int *argcp
, char ***argvp
)
196 char **argv
= *argvp
;
197 int len
= strlen(*argv
);
199 if (len
> 2 && strncmp(*argv
, "0x", 2) == 0) {
202 if (get_u8(&val
, *argv
, 16))
203 invarg("FLAG value is invalid", *argv
);
207 if (strcmp(*argv
, "noecn") == 0)
208 *flags
|= XFRM_STATE_NOECN
;
209 else if (strcmp(*argv
, "decap-dscp") == 0)
210 *flags
|= XFRM_STATE_DECAP_DSCP
;
211 else if (strcmp(*argv
, "nopmtudisc") == 0)
212 *flags
|= XFRM_STATE_NOPMTUDISC
;
213 else if (strcmp(*argv
, "wildrecv") == 0)
214 *flags
|= XFRM_STATE_WILDRECV
;
215 else if (strcmp(*argv
, "icmp") == 0)
216 *flags
|= XFRM_STATE_ICMP
;
217 else if (strcmp(*argv
, "af-unspec") == 0)
218 *flags
|= XFRM_STATE_AF_UNSPEC
;
219 else if (strcmp(*argv
, "align4") == 0)
220 *flags
|= XFRM_STATE_ALIGN4
;
221 else if (strcmp(*argv
, "esn") == 0)
222 *flags
|= XFRM_STATE_ESN
;
224 PREV_ARG(); /* back track */
240 static int xfrm_state_extra_flag_parse(__u32
*extra_flags
, int *argcp
, char ***argvp
)
243 char **argv
= *argvp
;
244 int len
= strlen(*argv
);
246 if (len
> 2 && strncmp(*argv
, "0x", 2) == 0) {
249 if (get_u32(&val
, *argv
, 16))
250 invarg("\"EXTRA-FLAG\" is invalid", *argv
);
254 if (strcmp(*argv
, "dont-encap-dscp") == 0)
255 *extra_flags
|= XFRM_SA_XFLAG_DONT_ENCAP_DSCP
;
257 PREV_ARG(); /* back track */
273 static int xfrm_offload_dir_parse(__u8
*dir
, int *argcp
, char ***argvp
)
276 char **argv
= *argvp
;
278 if (strcmp(*argv
, "in") == 0)
279 *dir
= XFRM_OFFLOAD_INBOUND
;
280 else if (strcmp(*argv
, "out") == 0)
283 invarg("DIR value is invalid", *argv
);
291 static int xfrm_state_modify(int cmd
, unsigned int flags
, int argc
, char **argv
)
293 struct rtnl_handle rth
;
296 struct xfrm_usersa_info xsinfo
;
297 char buf
[RTA_BUF_SIZE
];
299 .n
.nlmsg_len
= NLMSG_LENGTH(sizeof(req
.xsinfo
)),
300 .n
.nlmsg_flags
= NLM_F_REQUEST
| flags
,
302 .xsinfo
.family
= preferred_family
,
303 .xsinfo
.lft
.soft_byte_limit
= XFRM_INF
,
304 .xsinfo
.lft
.hard_byte_limit
= XFRM_INF
,
305 .xsinfo
.lft
.soft_packet_limit
= XFRM_INF
,
306 .xsinfo
.lft
.hard_packet_limit
= XFRM_INF
,
308 struct xfrm_replay_state replay
= {};
309 struct xfrm_replay_state_esn replay_esn
= {};
310 struct xfrm_user_offload xuo
= {};
311 unsigned int ifindex
= 0;
313 bool is_offload
= false;
314 __u32 replay_window
= 0;
315 __u32 seq
= 0, oseq
= 0, seq_hi
= 0, oseq_hi
= 0;
323 __u32 extra_flags
= 0;
324 struct xfrm_mark mark
= {0, 0};
326 struct xfrm_user_sec_ctx sctx
;
327 char str
[CTX_BUF_SIZE
];
329 __u32 output_mark
= 0;
332 if (strcmp(*argv
, "mode") == 0) {
334 xfrm_mode_parse(&req
.xsinfo
.mode
, &argc
, &argv
);
335 } else if (strcmp(*argv
, "mark") == 0) {
336 xfrm_parse_mark(&mark
, &argc
, &argv
);
337 } else if (strcmp(*argv
, "reqid") == 0) {
339 xfrm_reqid_parse(&req
.xsinfo
.reqid
, &argc
, &argv
);
340 } else if (strcmp(*argv
, "seq") == 0) {
342 xfrm_seq_parse(&req
.xsinfo
.seq
, &argc
, &argv
);
343 } else if (strcmp(*argv
, "replay-window") == 0) {
345 if (get_u32(&replay_window
, *argv
, 0))
346 invarg("value after \"replay-window\" is invalid", *argv
);
347 } else if (strcmp(*argv
, "replay-seq") == 0) {
349 if (get_u32(&seq
, *argv
, 0))
350 invarg("value after \"replay-seq\" is invalid", *argv
);
351 } else if (strcmp(*argv
, "replay-seq-hi") == 0) {
353 if (get_u32(&seq_hi
, *argv
, 0))
354 invarg("value after \"replay-seq-hi\" is invalid", *argv
);
355 } else if (strcmp(*argv
, "replay-oseq") == 0) {
357 if (get_u32(&oseq
, *argv
, 0))
358 invarg("value after \"replay-oseq\" is invalid", *argv
);
359 } else if (strcmp(*argv
, "replay-oseq-hi") == 0) {
361 if (get_u32(&oseq_hi
, *argv
, 0))
362 invarg("value after \"replay-oseq-hi\" is invalid", *argv
);
363 } else if (strcmp(*argv
, "flag") == 0) {
365 xfrm_state_flag_parse(&req
.xsinfo
.flags
, &argc
, &argv
);
366 } else if (strcmp(*argv
, "extra-flag") == 0) {
368 xfrm_state_extra_flag_parse(&extra_flags
, &argc
, &argv
);
369 } else if (strcmp(*argv
, "sel") == 0) {
371 preferred_family
= AF_UNSPEC
;
372 xfrm_selector_parse(&req
.xsinfo
.sel
, &argc
, &argv
);
373 preferred_family
= req
.xsinfo
.sel
.family
;
374 } else if (strcmp(*argv
, "limit") == 0) {
376 xfrm_lifetime_cfg_parse(&req
.xsinfo
.lft
, &argc
, &argv
);
377 } else if (strcmp(*argv
, "encap") == 0) {
378 struct xfrm_encap_tmpl encap
;
381 xfrm_encap_type_parse(&encap
.encap_type
, &argc
, &argv
);
383 if (get_be16(&encap
.encap_sport
, *argv
, 0))
384 invarg("SPORT value after \"encap\" is invalid", *argv
);
386 if (get_be16(&encap
.encap_dport
, *argv
, 0))
387 invarg("DPORT value after \"encap\" is invalid", *argv
);
389 get_addr(&oa
, *argv
, AF_UNSPEC
);
390 memcpy(&encap
.encap_oa
, &oa
.data
, sizeof(encap
.encap_oa
));
391 addattr_l(&req
.n
, sizeof(req
.buf
), XFRMA_ENCAP
,
392 (void *)&encap
, sizeof(encap
));
393 } else if (strcmp(*argv
, "coa") == 0) {
395 xfrm_address_t xcoa
= {};
398 duparg("coa", *argv
);
403 get_prefix(&coa
, *argv
, preferred_family
);
404 if (coa
.family
== AF_UNSPEC
)
405 invarg("value after \"coa\" has an unrecognized address family", *argv
);
406 if (coa
.bytelen
> sizeof(xcoa
))
407 invarg("value after \"coa\" is too large", *argv
);
409 memcpy(&xcoa
, &coa
.data
, coa
.bytelen
);
411 addattr_l(&req
.n
, sizeof(req
.buf
), XFRMA_COADDR
,
412 (void *)&xcoa
, sizeof(xcoa
));
413 } else if (strcmp(*argv
, "ctx") == 0) {
417 duparg("ctx", *argv
);
423 xfrm_sctx_parse((char *)&ctx
.str
, context
, &ctx
.sctx
);
424 addattr_l(&req
.n
, sizeof(req
.buf
), XFRMA_SEC_CTX
,
425 (void *)&ctx
, ctx
.sctx
.len
);
426 } else if (strcmp(*argv
, "offload") == 0) {
429 if (strcmp(*argv
, "dev") == 0) {
431 ifindex
= ll_name_to_index(*argv
);
433 invarg("value after \"offload dev\" is invalid", *argv
);
438 if (strcmp(*argv
, "dir") == 0) {
440 xfrm_offload_dir_parse(&dir
, &argc
, &argv
);
442 invarg("value after \"offload dir\" is invalid", *argv
);
445 } else if (strcmp(*argv
, "output-mark") == 0) {
447 if (get_u32(&output_mark
, *argv
, 0))
448 invarg("value after \"output-mark\" is invalid", *argv
);
450 /* try to assume ALGO */
451 int type
= xfrm_algotype_getbyname(*argv
);
455 case XFRMA_ALG_CRYPT
:
457 case XFRMA_ALG_AUTH_TRUNC
:
463 struct xfrm_algo alg
;
464 struct xfrm_algo_aead aead
;
465 struct xfrm_algo_auth auth
;
467 char buf
[XFRM_ALGO_KEY_BUF_SIZE
];
470 __u32 icvlen
, trunclen
;
477 if (ealgop
|| aalgop
|| aeadop
)
478 duparg("ALGO-TYPE", *argv
);
481 case XFRMA_ALG_CRYPT
:
482 if (ealgop
|| aeadop
)
483 duparg("ALGO-TYPE", *argv
);
487 case XFRMA_ALG_AUTH_TRUNC
:
488 if (aalgop
|| aeadop
)
489 duparg("ALGO-TYPE", *argv
);
494 duparg("ALGO-TYPE", *argv
);
499 invarg("ALGO-TYPE value is invalid\n", *argv
);
503 missarg("ALGO-NAME");
509 case XFRMA_ALG_CRYPT
:
511 case XFRMA_ALG_AUTH_TRUNC
:
513 missarg("ALGO-KEYMAT");
519 buf
= alg
.u
.alg
.alg_key
;
520 len
= sizeof(alg
.u
.alg
);
525 missarg("ALGO-ICV-LEN");
527 if (get_u32(&icvlen
, *argv
, 0))
528 invarg("ALGO-ICV-LEN value is invalid",
530 alg
.u
.aead
.alg_icv_len
= icvlen
;
532 buf
= alg
.u
.aead
.alg_key
;
533 len
= sizeof(alg
.u
.aead
);
535 case XFRMA_ALG_AUTH_TRUNC
:
537 missarg("ALGO-TRUNC-LEN");
539 if (get_u32(&trunclen
, *argv
, 0))
540 invarg("ALGO-TRUNC-LEN value is invalid",
542 alg
.u
.auth
.alg_trunc_len
= trunclen
;
544 buf
= alg
.u
.auth
.alg_key
;
545 len
= sizeof(alg
.u
.auth
);
549 xfrm_algo_parse((void *)&alg
, type
, name
, key
,
550 buf
, sizeof(alg
.buf
));
551 len
+= alg
.u
.alg
.alg_key_len
/ 8;
553 addattr_l(&req
.n
, sizeof(req
.buf
), type
,
558 /* try to assume ID */
560 invarg("unknown", *argv
);
564 xfrm_id_parse(&req
.xsinfo
.saddr
, &req
.xsinfo
.id
,
565 &req
.xsinfo
.family
, 0, &argc
, &argv
);
566 if (preferred_family
== AF_UNSPEC
)
567 preferred_family
= req
.xsinfo
.family
;
573 if (req
.xsinfo
.flags
& XFRM_STATE_ESN
&&
574 replay_window
== 0) {
575 fprintf(stderr
, "Error: esn flag set without replay-window.\n");
579 if (replay_window
> XFRMA_REPLAY_ESN_MAX
) {
581 "Error: replay-window (%u) > XFRMA_REPLAY_ESN_MAX (%u).\n",
582 replay_window
, XFRMA_REPLAY_ESN_MAX
);
587 xuo
.ifindex
= ifindex
;
589 addattr_l(&req
.n
, sizeof(req
.buf
), XFRMA_OFFLOAD_DEV
, &xuo
,
592 if (req
.xsinfo
.flags
& XFRM_STATE_ESN
||
593 replay_window
> (sizeof(replay
.bitmap
) * 8)) {
594 replay_esn
.seq
= seq
;
595 replay_esn
.oseq
= oseq
;
596 replay_esn
.seq_hi
= seq_hi
;
597 replay_esn
.oseq_hi
= oseq_hi
;
598 replay_esn
.replay_window
= replay_window
;
599 replay_esn
.bmp_len
= (replay_window
+ sizeof(__u32
) * 8 - 1) /
601 addattr_l(&req
.n
, sizeof(req
.buf
), XFRMA_REPLAY_ESN_VAL
,
602 &replay_esn
, sizeof(replay_esn
));
607 addattr_l(&req
.n
, sizeof(req
.buf
), XFRMA_REPLAY_VAL
,
608 &replay
, sizeof(replay
));
610 req
.xsinfo
.replay_window
= replay_window
;
614 addattr32(&req
.n
, sizeof(req
.buf
), XFRMA_SA_EXTRA_FLAGS
,
618 fprintf(stderr
, "Not enough information: ID is required\n");
623 int r
= addattr_l(&req
.n
, sizeof(req
.buf
), XFRMA_MARK
,
624 (void *)&mark
, sizeof(mark
));
626 fprintf(stderr
, "XFRMA_MARK failed\n");
631 if (xfrm_xfrmproto_is_ipsec(req
.xsinfo
.id
.proto
)) {
632 switch (req
.xsinfo
.mode
) {
633 case XFRM_MODE_TRANSPORT
:
634 case XFRM_MODE_TUNNEL
:
637 if (req
.xsinfo
.id
.proto
== IPPROTO_ESP
)
640 fprintf(stderr
, "MODE value is invalid with XFRM-PROTO value \"%s\"\n",
641 strxf_xfrmproto(req
.xsinfo
.id
.proto
));
645 switch (req
.xsinfo
.id
.proto
) {
648 fprintf(stderr
, "ALGO-TYPE value \"%s\" is invalid with XFRM-PROTO value \"%s\"\n",
649 strxf_algotype(XFRMA_ALG_COMP
),
650 strxf_xfrmproto(req
.xsinfo
.id
.proto
));
653 if (!ealgop
&& !aeadop
) {
654 fprintf(stderr
, "ALGO-TYPE value \"%s\" or \"%s\" is required with XFRM-PROTO value \"%s\"\n",
655 strxf_algotype(XFRMA_ALG_CRYPT
),
656 strxf_algotype(XFRMA_ALG_AEAD
),
657 strxf_xfrmproto(req
.xsinfo
.id
.proto
));
662 if (ealgop
|| aeadop
|| calgop
) {
663 fprintf(stderr
, "ALGO-TYPE values \"%s\", \"%s\", and \"%s\" are invalid with XFRM-PROTO value \"%s\"\n",
664 strxf_algotype(XFRMA_ALG_CRYPT
),
665 strxf_algotype(XFRMA_ALG_AEAD
),
666 strxf_algotype(XFRMA_ALG_COMP
),
667 strxf_xfrmproto(req
.xsinfo
.id
.proto
));
671 fprintf(stderr
, "ALGO-TYPE value \"%s\" or \"%s\" is required with XFRM-PROTO value \"%s\"\n",
672 strxf_algotype(XFRMA_ALG_AUTH
),
673 strxf_algotype(XFRMA_ALG_AUTH_TRUNC
),
674 strxf_xfrmproto(req
.xsinfo
.id
.proto
));
679 if (ealgop
|| aalgop
|| aeadop
) {
680 fprintf(stderr
, "ALGO-TYPE values \"%s\", \"%s\", \"%s\", and \"%s\" are invalid with XFRM-PROTO value \"%s\"\n",
681 strxf_algotype(XFRMA_ALG_CRYPT
),
682 strxf_algotype(XFRMA_ALG_AUTH
),
683 strxf_algotype(XFRMA_ALG_AUTH_TRUNC
),
684 strxf_algotype(XFRMA_ALG_AEAD
),
685 strxf_xfrmproto(req
.xsinfo
.id
.proto
));
689 fprintf(stderr
, "ALGO-TYPE value \"%s\" is required with XFRM-PROTO value \"%s\"\n",
690 strxf_algotype(XFRMA_ALG_COMP
),
691 strxf_xfrmproto(req
.xsinfo
.id
.proto
));
697 if (ealgop
|| aalgop
|| aeadop
|| calgop
) {
698 fprintf(stderr
, "ALGO is invalid with XFRM-PROTO value \"%s\"\n",
699 strxf_xfrmproto(req
.xsinfo
.id
.proto
));
704 if (xfrm_xfrmproto_is_ro(req
.xsinfo
.id
.proto
)) {
705 switch (req
.xsinfo
.mode
) {
706 case XFRM_MODE_ROUTEOPTIMIZATION
:
707 case XFRM_MODE_IN_TRIGGER
:
710 fprintf(stderr
, "\"mode\" is required with XFRM-PROTO value \"%s\"\n",
711 strxf_xfrmproto(req
.xsinfo
.id
.proto
));
714 fprintf(stderr
, "MODE value is invalid with XFRM-PROTO value \"%s\"\n",
715 strxf_xfrmproto(req
.xsinfo
.id
.proto
));
720 fprintf(stderr
, "\"coa\" is required with XFRM-PROTO value \"%s\"\n",
721 strxf_xfrmproto(req
.xsinfo
.id
.proto
));
726 fprintf(stderr
, "\"coa\" is invalid with XFRM-PROTO value \"%s\"\n",
727 strxf_xfrmproto(req
.xsinfo
.id
.proto
));
733 addattr32(&req
.n
, sizeof(req
.buf
), XFRMA_OUTPUT_MARK
, output_mark
);
735 if (rtnl_open_byproto(&rth
, 0, NETLINK_XFRM
) < 0)
738 if (req
.xsinfo
.family
== AF_UNSPEC
)
739 req
.xsinfo
.family
= AF_INET
;
741 if (rtnl_talk(&rth
, &req
.n
, NULL
) < 0)
749 static int xfrm_state_allocspi(int argc
, char **argv
)
751 struct rtnl_handle rth
;
754 struct xfrm_userspi_info xspi
;
755 char buf
[RTA_BUF_SIZE
];
757 .n
.nlmsg_len
= NLMSG_LENGTH(sizeof(req
.xspi
)),
758 .n
.nlmsg_flags
= NLM_F_REQUEST
,
759 .n
.nlmsg_type
= XFRM_MSG_ALLOCSPI
,
760 .xspi
.info
.family
= preferred_family
,
762 .xspi
.lft
.soft_byte_limit
= XFRM_INF
,
763 .xspi
.lft
.hard_byte_limit
= XFRM_INF
,
764 .xspi
.lft
.soft_packet_limit
= XFRM_INF
,
765 .xspi
.lft
.hard_packet_limit
= XFRM_INF
,
771 struct xfrm_mark mark
= {0, 0};
772 struct nlmsghdr
*answer
;
775 if (strcmp(*argv
, "mode") == 0) {
777 xfrm_mode_parse(&req
.xspi
.info
.mode
, &argc
, &argv
);
778 } else if (strcmp(*argv
, "mark") == 0) {
779 xfrm_parse_mark(&mark
, &argc
, &argv
);
780 } else if (strcmp(*argv
, "reqid") == 0) {
782 xfrm_reqid_parse(&req
.xspi
.info
.reqid
, &argc
, &argv
);
783 } else if (strcmp(*argv
, "seq") == 0) {
785 xfrm_seq_parse(&req
.xspi
.info
.seq
, &argc
, &argv
);
786 } else if (strcmp(*argv
, "min") == 0) {
788 duparg("min", *argv
);
793 if (get_u32(&req
.xspi
.min
, *argv
, 0))
794 invarg("value after \"min\" is invalid", *argv
);
795 } else if (strcmp(*argv
, "max") == 0) {
797 duparg("max", *argv
);
802 if (get_u32(&req
.xspi
.max
, *argv
, 0))
803 invarg("value after \"max\" is invalid", *argv
);
805 /* try to assume ID */
807 invarg("unknown", *argv
);
811 xfrm_id_parse(&req
.xspi
.info
.saddr
, &req
.xspi
.info
.id
,
812 &req
.xspi
.info
.family
, 0, &argc
, &argv
);
813 if (req
.xspi
.info
.id
.spi
) {
814 fprintf(stderr
, "\"spi\" is invalid\n");
817 if (preferred_family
== AF_UNSPEC
)
818 preferred_family
= req
.xspi
.info
.family
;
824 fprintf(stderr
, "Not enough information: ID is required\n");
830 fprintf(stderr
, "\"max\" is missing\n");
833 if (req
.xspi
.min
> req
.xspi
.max
) {
834 fprintf(stderr
, "value after \"min\" is larger than value after \"max\"\n");
839 fprintf(stderr
, "\"min\" is missing\n");
843 /* XXX: Default value defined in PF_KEY;
844 * See kernel's net/key/af_key.c(pfkey_getspi).
846 req
.xspi
.min
= 0x100;
847 req
.xspi
.max
= 0x0fffffff;
849 /* XXX: IPCOMP spi is 16-bits;
850 * See kernel's net/xfrm/xfrm_user(verify_userspi_info).
852 if (req
.xspi
.info
.id
.proto
== IPPROTO_COMP
)
853 req
.xspi
.max
= 0xffff;
856 if (mark
.m
& mark
.v
) {
857 int r
= addattr_l(&req
.n
, sizeof(req
.buf
), XFRMA_MARK
,
858 (void *)&mark
, sizeof(mark
));
860 fprintf(stderr
, "XFRMA_MARK failed\n");
865 if (rtnl_open_byproto(&rth
, 0, NETLINK_XFRM
) < 0)
868 if (req
.xspi
.info
.family
== AF_UNSPEC
)
869 req
.xspi
.info
.family
= AF_INET
;
872 if (rtnl_talk(&rth
, &req
.n
, &answer
) < 0)
875 if (xfrm_state_print(answer
, (void *)stdout
) < 0) {
876 fprintf(stderr
, "An error :-)\n");
886 static int xfrm_state_filter_match(struct xfrm_usersa_info
*xsinfo
)
891 if (filter
.id_src_mask
)
892 if (xfrm_addr_match(&xsinfo
->saddr
, &filter
.xsinfo
.saddr
,
895 if (filter
.id_dst_mask
)
896 if (xfrm_addr_match(&xsinfo
->id
.daddr
, &filter
.xsinfo
.id
.daddr
,
899 if ((xsinfo
->id
.proto
^filter
.xsinfo
.id
.proto
)&filter
.id_proto_mask
)
901 if ((xsinfo
->id
.spi
^filter
.xsinfo
.id
.spi
)&filter
.id_spi_mask
)
903 if ((xsinfo
->mode
^filter
.xsinfo
.mode
)&filter
.mode_mask
)
905 if ((xsinfo
->reqid
^filter
.xsinfo
.reqid
)&filter
.reqid_mask
)
907 if (filter
.state_flags_mask
)
908 if ((xsinfo
->flags
& filter
.xsinfo
.flags
) == 0)
914 int xfrm_state_print(struct nlmsghdr
*n
, void *arg
)
916 FILE *fp
= (FILE *)arg
;
917 struct rtattr
*tb
[XFRMA_MAX
+1];
919 struct xfrm_usersa_info
*xsinfo
= NULL
;
920 struct xfrm_user_expire
*xexp
= NULL
;
921 struct xfrm_usersa_id
*xsid
= NULL
;
922 int len
= n
->nlmsg_len
;
924 if (n
->nlmsg_type
!= XFRM_MSG_NEWSA
&&
925 n
->nlmsg_type
!= XFRM_MSG_DELSA
&&
926 n
->nlmsg_type
!= XFRM_MSG_UPDSA
&&
927 n
->nlmsg_type
!= XFRM_MSG_EXPIRE
) {
928 fprintf(stderr
, "Not a state: %08x %08x %08x\n",
929 n
->nlmsg_len
, n
->nlmsg_type
, n
->nlmsg_flags
);
933 if (n
->nlmsg_type
== XFRM_MSG_DELSA
) {
934 /* Don't blame me for this .. Herbert made me do it */
935 xsid
= NLMSG_DATA(n
);
936 len
-= NLMSG_SPACE(sizeof(*xsid
));
937 } else if (n
->nlmsg_type
== XFRM_MSG_EXPIRE
) {
938 xexp
= NLMSG_DATA(n
);
939 xsinfo
= &xexp
->state
;
940 len
-= NLMSG_SPACE(sizeof(*xexp
));
943 xsinfo
= NLMSG_DATA(n
);
944 len
-= NLMSG_SPACE(sizeof(*xsinfo
));
948 fprintf(stderr
, "BUG: wrong nlmsg len %d\n", len
);
952 if (xsinfo
&& !xfrm_state_filter_match(xsinfo
))
955 if (n
->nlmsg_type
== XFRM_MSG_DELSA
)
956 fprintf(fp
, "Deleted ");
957 else if (n
->nlmsg_type
== XFRM_MSG_UPDSA
)
958 fprintf(fp
, "Updated ");
959 else if (n
->nlmsg_type
== XFRM_MSG_EXPIRE
)
960 fprintf(fp
, "Expired ");
962 if (n
->nlmsg_type
== XFRM_MSG_DELSA
)
963 rta
= XFRMSID_RTA(xsid
);
964 else if (n
->nlmsg_type
== XFRM_MSG_EXPIRE
)
965 rta
= XFRMEXP_RTA(xexp
);
967 rta
= XFRMS_RTA(xsinfo
);
969 parse_rtattr(tb
, XFRMA_MAX
, rta
, len
);
971 if (n
->nlmsg_type
== XFRM_MSG_DELSA
) {
972 /* xfrm_policy_id_print(); */
975 fprintf(stderr
, "Buggy XFRM_MSG_DELSA: no XFRMA_SA\n");
978 if (RTA_PAYLOAD(tb
[XFRMA_SA
]) < sizeof(*xsinfo
)) {
979 fprintf(stderr
, "Buggy XFRM_MSG_DELPOLICY: too short XFRMA_POLICY len\n");
982 xsinfo
= RTA_DATA(tb
[XFRMA_SA
]);
985 xfrm_state_info_print(xsinfo
, tb
, fp
, NULL
, NULL
);
987 if (n
->nlmsg_type
== XFRM_MSG_EXPIRE
) {
989 fprintf(fp
, "hard %u", xexp
->hard
);
990 fprintf(fp
, "%s", _SL_
);
1000 static int xfrm_state_get_or_delete(int argc
, char **argv
, int delete)
1002 struct rtnl_handle rth
;
1005 struct xfrm_usersa_id xsid
;
1006 char buf
[RTA_BUF_SIZE
];
1008 .n
.nlmsg_len
= NLMSG_LENGTH(sizeof(req
.xsid
)),
1009 .n
.nlmsg_flags
= NLM_F_REQUEST
,
1010 .n
.nlmsg_type
= delete ? XFRM_MSG_DELSA
: XFRM_MSG_GETSA
,
1011 .xsid
.family
= preferred_family
,
1015 struct xfrm_mark mark
= {0, 0};
1018 xfrm_address_t saddr
;
1020 if (strcmp(*argv
, "mark") == 0) {
1021 xfrm_parse_mark(&mark
, &argc
, &argv
);
1024 invarg("unknown", *argv
);
1028 memset(&id
, 0, sizeof(id
));
1029 memset(&saddr
, 0, sizeof(saddr
));
1030 xfrm_id_parse(&saddr
, &id
, &req
.xsid
.family
, 0,
1033 memcpy(&req
.xsid
.daddr
, &id
.daddr
, sizeof(req
.xsid
.daddr
));
1034 req
.xsid
.spi
= id
.spi
;
1035 req
.xsid
.proto
= id
.proto
;
1037 addattr_l(&req
.n
, sizeof(req
.buf
), XFRMA_SRCADDR
,
1038 (void *)&saddr
, sizeof(saddr
));
1044 if (mark
.m
& mark
.v
) {
1045 int r
= addattr_l(&req
.n
, sizeof(req
.buf
), XFRMA_MARK
,
1046 (void *)&mark
, sizeof(mark
));
1048 fprintf(stderr
, "XFRMA_MARK failed\n");
1053 if (rtnl_open_byproto(&rth
, 0, NETLINK_XFRM
) < 0)
1056 if (req
.xsid
.family
== AF_UNSPEC
)
1057 req
.xsid
.family
= AF_INET
;
1060 if (rtnl_talk(&rth
, &req
.n
, NULL
) < 0)
1063 struct nlmsghdr
*answer
;
1065 if (rtnl_talk(&rth
, &req
.n
, &answer
) < 0)
1068 if (xfrm_state_print(answer
, (void *)stdout
) < 0) {
1069 fprintf(stderr
, "An error :-)\n");
1082 * With an existing state of nlmsg, make new nlmsg for deleting the state
1083 * and store it to buffer.
1085 static int xfrm_state_keep(struct nlmsghdr
*n
, void *arg
)
1087 struct xfrm_buffer
*xb
= (struct xfrm_buffer
*)arg
;
1088 struct rtnl_handle
*rth
= xb
->rth
;
1089 struct xfrm_usersa_info
*xsinfo
= NLMSG_DATA(n
);
1090 int len
= n
->nlmsg_len
;
1091 struct nlmsghdr
*new_n
;
1092 struct xfrm_usersa_id
*xsid
;
1093 struct rtattr
*tb
[XFRMA_MAX
+1];
1095 if (n
->nlmsg_type
!= XFRM_MSG_NEWSA
) {
1096 fprintf(stderr
, "Not a state: %08x %08x %08x\n",
1097 n
->nlmsg_len
, n
->nlmsg_type
, n
->nlmsg_flags
);
1101 len
-= NLMSG_LENGTH(sizeof(*xsinfo
));
1103 fprintf(stderr
, "BUG: wrong nlmsg len %d\n", len
);
1107 if (!xfrm_state_filter_match(xsinfo
))
1110 if (xb
->offset
> xb
->size
) {
1111 fprintf(stderr
, "State buffer overflow\n");
1115 new_n
= (struct nlmsghdr
*)(xb
->buf
+ xb
->offset
);
1116 new_n
->nlmsg_len
= NLMSG_LENGTH(sizeof(*xsid
));
1117 new_n
->nlmsg_flags
= NLM_F_REQUEST
;
1118 new_n
->nlmsg_type
= XFRM_MSG_DELSA
;
1119 new_n
->nlmsg_seq
= ++rth
->seq
;
1121 xsid
= NLMSG_DATA(new_n
);
1122 xsid
->family
= xsinfo
->family
;
1123 memcpy(&xsid
->daddr
, &xsinfo
->id
.daddr
, sizeof(xsid
->daddr
));
1124 xsid
->spi
= xsinfo
->id
.spi
;
1125 xsid
->proto
= xsinfo
->id
.proto
;
1127 addattr_l(new_n
, xb
->size
, XFRMA_SRCADDR
, &xsinfo
->saddr
,
1128 sizeof(xsid
->daddr
));
1130 parse_rtattr(tb
, XFRMA_MAX
, XFRMS_RTA(xsinfo
), len
);
1132 if (tb
[XFRMA_MARK
]) {
1133 int r
= addattr_l(new_n
, xb
->size
, XFRMA_MARK
,
1134 (void *)RTA_DATA(tb
[XFRMA_MARK
]), tb
[XFRMA_MARK
]->rta_len
);
1136 fprintf(stderr
, "%s: XFRMA_MARK failed\n", __func__
);
1141 xb
->offset
+= new_n
->nlmsg_len
;
1147 static int xfrm_state_list_or_deleteall(int argc
, char **argv
, int deleteall
)
1150 struct rtnl_handle rth
;
1154 filter
.xsinfo
.family
= preferred_family
;
1157 if (strcmp(*argv
, "mode") == 0) {
1159 xfrm_mode_parse(&filter
.xsinfo
.mode
, &argc
, &argv
);
1161 filter
.mode_mask
= XFRM_FILTER_MASK_FULL
;
1163 } else if (strcmp(*argv
, "reqid") == 0) {
1165 xfrm_reqid_parse(&filter
.xsinfo
.reqid
, &argc
, &argv
);
1167 filter
.reqid_mask
= XFRM_FILTER_MASK_FULL
;
1169 } else if (strcmp(*argv
, "flag") == 0) {
1171 xfrm_state_flag_parse(&filter
.xsinfo
.flags
, &argc
, &argv
);
1173 filter
.state_flags_mask
= XFRM_FILTER_MASK_FULL
;
1177 invarg("unknown", *argv
);
1181 xfrm_id_parse(&filter
.xsinfo
.saddr
, &filter
.xsinfo
.id
,
1182 &filter
.xsinfo
.family
, 1, &argc
, &argv
);
1183 if (preferred_family
== AF_UNSPEC
)
1184 preferred_family
= filter
.xsinfo
.family
;
1189 if (rtnl_open_byproto(&rth
, 0, NETLINK_XFRM
) < 0)
1193 struct xfrm_buffer xb
;
1194 char buf
[NLMSG_DELETEALL_BUF_SIZE
];
1198 xb
.size
= sizeof(buf
);
1201 for (i
= 0; ; i
++) {
1204 char buf
[NLMSG_BUF_SIZE
];
1206 .n
.nlmsg_len
= NLMSG_HDRLEN
,
1207 .n
.nlmsg_flags
= NLM_F_DUMP
| NLM_F_REQUEST
,
1208 .n
.nlmsg_type
= XFRM_MSG_GETSA
,
1209 .n
.nlmsg_seq
= rth
.dump
= ++rth
.seq
,
1216 fprintf(stderr
, "Delete-all round = %d\n", i
);
1218 if (rtnl_send(&rth
, (void *)&req
, req
.n
.nlmsg_len
) < 0) {
1219 perror("Cannot send dump request");
1223 if (rtnl_dump_filter(&rth
, xfrm_state_keep
, &xb
) < 0) {
1224 fprintf(stderr
, "Delete-all terminated\n");
1227 if (xb
.nlmsg_count
== 0) {
1229 fprintf(stderr
, "Delete-all completed\n");
1233 if (rtnl_send_check(&rth
, xb
.buf
, xb
.offset
) < 0) {
1234 perror("Failed to send delete-all request\n");
1238 fprintf(stderr
, "Delete-all nlmsg count = %d\n", xb
.nlmsg_count
);
1245 struct xfrm_address_filter addrfilter
= {
1246 .saddr
= filter
.xsinfo
.saddr
,
1247 .daddr
= filter
.xsinfo
.id
.daddr
,
1248 .family
= filter
.xsinfo
.family
,
1249 .splen
= filter
.id_src_mask
,
1250 .dplen
= filter
.id_dst_mask
,
1254 char buf
[NLMSG_BUF_SIZE
];
1256 .n
.nlmsg_len
= NLMSG_HDRLEN
,
1257 .n
.nlmsg_flags
= NLM_F_DUMP
| NLM_F_REQUEST
,
1258 .n
.nlmsg_type
= XFRM_MSG_GETSA
,
1259 .n
.nlmsg_seq
= rth
.dump
= ++rth
.seq
,
1262 if (filter
.xsinfo
.id
.proto
)
1263 addattr8(&req
.n
, sizeof(req
), XFRMA_PROTO
,
1264 filter
.xsinfo
.id
.proto
);
1265 addattr_l(&req
.n
, sizeof(req
), XFRMA_ADDRESS_FILTER
,
1266 &addrfilter
, sizeof(addrfilter
));
1268 if (rtnl_send(&rth
, (void *)&req
, req
.n
.nlmsg_len
) < 0) {
1269 perror("Cannot send dump request");
1273 if (rtnl_dump_filter(&rth
, xfrm_state_print
, stdout
) < 0) {
1274 fprintf(stderr
, "Dump terminated\n");
1284 static int print_sadinfo(struct nlmsghdr
*n
, void *arg
)
1286 FILE *fp
= (FILE *)arg
;
1287 __u32
*f
= NLMSG_DATA(n
);
1288 struct rtattr
*tb
[XFRMA_SAD_MAX
+1];
1290 int len
= n
->nlmsg_len
;
1292 len
-= NLMSG_LENGTH(sizeof(__u32
));
1294 fprintf(stderr
, "SADinfo: Wrong len %d\n", len
);
1298 rta
= XFRMSAPD_RTA(f
);
1299 parse_rtattr(tb
, XFRMA_SAD_MAX
, rta
, len
);
1301 if (tb
[XFRMA_SAD_CNT
]) {
1304 fprintf(fp
, "\t SAD");
1305 cnt
= rta_getattr_u32(tb
[XFRMA_SAD_CNT
]);
1306 fprintf(fp
, " count %u", cnt
);
1308 fprintf(fp
, "BAD SAD info returned\n");
1313 if (tb
[XFRMA_SAD_HINFO
]) {
1314 struct xfrmu_sadhinfo
*si
;
1316 if (RTA_PAYLOAD(tb
[XFRMA_SAD_HINFO
]) < sizeof(*si
)) {
1317 fprintf(fp
, "BAD SAD length returned\n");
1321 si
= RTA_DATA(tb
[XFRMA_SAD_HINFO
]);
1322 fprintf(fp
, " (buckets ");
1323 fprintf(fp
, "count %d", si
->sadhcnt
);
1324 fprintf(fp
, " Max %d", si
->sadhmcnt
);
1333 static int xfrm_sad_getinfo(int argc
, char **argv
)
1335 struct rtnl_handle rth
;
1340 .n
.nlmsg_len
= NLMSG_LENGTH(sizeof(req
.flags
)),
1341 .n
.nlmsg_flags
= NLM_F_REQUEST
,
1342 .n
.nlmsg_type
= XFRM_MSG_GETSADINFO
,
1343 .flags
= 0XFFFFFFFF,
1345 struct nlmsghdr
*answer
;
1347 if (rtnl_open_byproto(&rth
, 0, NETLINK_XFRM
) < 0)
1350 if (rtnl_talk(&rth
, &req
.n
, &answer
) < 0)
1353 print_sadinfo(answer
, (void *)stdout
);
1361 static int xfrm_state_flush(int argc
, char **argv
)
1363 struct rtnl_handle rth
;
1366 struct xfrm_usersa_flush xsf
;
1368 .n
.nlmsg_len
= NLMSG_LENGTH(sizeof(req
.xsf
)),
1369 .n
.nlmsg_flags
= NLM_F_REQUEST
,
1370 .n
.nlmsg_type
= XFRM_MSG_FLUSHSA
,
1372 char *protop
= NULL
;
1375 if (strcmp(*argv
, "proto") == 0) {
1379 duparg("proto", *argv
);
1384 ret
= xfrm_xfrmproto_getbyname(*argv
);
1386 invarg("XFRM-PROTO value is invalid", *argv
);
1388 req
.xsf
.proto
= (__u8
)ret
;
1390 invarg("unknown", *argv
);
1395 if (rtnl_open_byproto(&rth
, 0, NETLINK_XFRM
) < 0)
1399 fprintf(stderr
, "Flush state with XFRM-PROTO value \"%s\"\n",
1400 strxf_xfrmproto(req
.xsf
.proto
));
1402 if (rtnl_talk(&rth
, &req
.n
, NULL
) < 0)
1410 int do_xfrm_state(int argc
, char **argv
)
1413 return xfrm_state_list_or_deleteall(0, NULL
, 0);
1415 if (matches(*argv
, "add") == 0)
1416 return xfrm_state_modify(XFRM_MSG_NEWSA
, 0,
1418 if (matches(*argv
, "update") == 0)
1419 return xfrm_state_modify(XFRM_MSG_UPDSA
, 0,
1421 if (matches(*argv
, "allocspi") == 0)
1422 return xfrm_state_allocspi(argc
-1, argv
+1);
1423 if (matches(*argv
, "delete") == 0)
1424 return xfrm_state_get_or_delete(argc
-1, argv
+1, 1);
1425 if (matches(*argv
, "deleteall") == 0 || matches(*argv
, "delall") == 0)
1426 return xfrm_state_list_or_deleteall(argc
-1, argv
+1, 1);
1427 if (matches(*argv
, "list") == 0 || matches(*argv
, "show") == 0
1428 || matches(*argv
, "lst") == 0)
1429 return xfrm_state_list_or_deleteall(argc
-1, argv
+1, 0);
1430 if (matches(*argv
, "get") == 0)
1431 return xfrm_state_get_or_delete(argc
-1, argv
+1, 0);
1432 if (matches(*argv
, "flush") == 0)
1433 return xfrm_state_flush(argc
-1, argv
+1);
1434 if (matches(*argv
, "count") == 0) {
1435 return xfrm_sad_getinfo(argc
, argv
);
1437 if (matches(*argv
, "help") == 0)
1439 fprintf(stderr
, "Command \"%s\" is unknown, try \"ip xfrm state help\".\n", *argv
);