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>.
21 * Masahide NAKAMURA @USAGI
28 #include <sys/socket.h>
30 #include <linux/xfrm.h>
31 #include <linux/ipsec.h>
34 #define IPPROTO_MH 135
37 #define XFRMS_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_usersa_info))))
38 #define XFRMS_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_usersa_info))
40 #define XFRMP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_userpolicy_info))))
41 #define XFRMP_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_userpoilcy_info))
43 #define XFRMSID_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_usersa_id))))
44 #define XFRMSID_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_usersa_id))
46 #define XFRMPID_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_userpolicy_id))))
47 #define XFRMPID_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_userpoilcy_id))
49 #define XFRMACQ_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_acquire))))
50 #define XFRMEXP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_expire))))
51 #define XFRMPEXP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_polexpire))))
53 #define XFRMREP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_report))))
55 #define XFRMSAPD_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(__u32))))
56 #define XFRM_FLAG_PRINT(fp, flags, f, s) \
60 fprintf(fp, s "%s", (flags ? " " : "")); \
70 struct rtnl_handle
*rth
;
76 struct xfrm_usersa_info xsinfo
;
83 __u8 state_flags_mask
;
85 struct xfrm_userpolicy_info xpinfo
;
90 __u8 upspec_proto_mask
;
91 __u16 upspec_sport_mask
;
92 __u16 upspec_dport_mask
;
96 __u8 policy_flags_mask
;
103 #define XFRM_FILTER_MASK_FULL (~0)
105 extern struct xfrm_filter filter
;
107 int xfrm_state_print(struct nlmsghdr
*n
, void *arg
);
108 int xfrm_state_print_nokeys(struct nlmsghdr
*n
, void *arg
);
109 int xfrm_policy_print(struct nlmsghdr
*n
, void *arg
);
110 int do_xfrm_state(int argc
, char **argv
);
111 int do_xfrm_policy(int argc
, char **argv
);
112 int do_xfrm_monitor(int argc
, char **argv
);
114 int xfrm_addr_match(xfrm_address_t
*x1
, xfrm_address_t
*x2
, int bits
);
115 int xfrm_xfrmproto_is_ipsec(__u8 proto
);
116 int xfrm_xfrmproto_is_ro(__u8 proto
);
117 int xfrm_xfrmproto_getbyname(char *name
);
118 int xfrm_algotype_getbyname(char *name
);
119 int xfrm_parse_mark(struct xfrm_mark
*mark
, int *argcp
, char ***argvp
);
120 const char *strxf_xfrmproto(__u8 proto
);
121 const char *strxf_algotype(int type
);
122 const char *strxf_mask32(__u32 mask
);
123 const char *strxf_proto(__u8 proto
);
124 const char *strxf_ptype(__u8 ptype
);
125 void xfrm_selector_print(struct xfrm_selector
*sel
, __u16 family
,
126 FILE *fp
, const char *prefix
);
127 void xfrm_xfrma_print(struct rtattr
*tb
[], __u16 family
,
128 FILE *fp
, const char *prefix
, bool nokeys
);
129 void xfrm_state_info_print(struct xfrm_usersa_info
*xsinfo
,
130 struct rtattr
*tb
[], FILE *fp
, const char *prefix
,
131 const char *title
, bool nokeys
);
132 void xfrm_policy_info_print(struct xfrm_userpolicy_info
*xpinfo
,
133 struct rtattr
*tb
[], FILE *fp
, const char *prefix
,
135 int xfrm_id_parse(xfrm_address_t
*saddr
, struct xfrm_id
*id
, __u16
*family
,
136 int loose
, int *argcp
, char ***argvp
);
137 int xfrm_mode_parse(__u8
*mode
, int *argcp
, char ***argvp
);
138 int xfrm_encap_type_parse(__u16
*type
, int *argcp
, char ***argvp
);
139 int xfrm_reqid_parse(__u32
*reqid
, int *argcp
, char ***argvp
);
140 int xfrm_selector_parse(struct xfrm_selector
*sel
, int *argcp
, char ***argvp
);
141 int xfrm_lifetime_cfg_parse(struct xfrm_lifetime_cfg
*lft
,
142 int *argcp
, char ***argvp
);
143 int xfrm_sctx_parse(char *ctxstr
, char *context
,
144 struct xfrm_user_sec_ctx
*sctx
);