xref: /aosp_15_r20/external/iproute2/ip/xfrm.h (revision de1e4e894b0c224df933550f0afdecc354b238c4)
1*de1e4e89SAndroid Build Coastguard Worker /* $USAGI: $ */
2*de1e4e89SAndroid Build Coastguard Worker 
3*de1e4e89SAndroid Build Coastguard Worker /*
4*de1e4e89SAndroid Build Coastguard Worker  * Copyright (C)2004 USAGI/WIDE Project
5*de1e4e89SAndroid Build Coastguard Worker  *
6*de1e4e89SAndroid Build Coastguard Worker  * This program is free software; you can redistribute it and/or modify
7*de1e4e89SAndroid Build Coastguard Worker  * it under the terms of the GNU General Public License as published by
8*de1e4e89SAndroid Build Coastguard Worker  * the Free Software Foundation; either version 2 of the License, or
9*de1e4e89SAndroid Build Coastguard Worker  * (at your option) any later version.
10*de1e4e89SAndroid Build Coastguard Worker  *
11*de1e4e89SAndroid Build Coastguard Worker  * This program is distributed in the hope that it will be useful,
12*de1e4e89SAndroid Build Coastguard Worker  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*de1e4e89SAndroid Build Coastguard Worker  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*de1e4e89SAndroid Build Coastguard Worker  * GNU General Public License for more details.
15*de1e4e89SAndroid Build Coastguard Worker  *
16*de1e4e89SAndroid Build Coastguard Worker  * You should have received a copy of the GNU General Public License
17*de1e4e89SAndroid Build Coastguard Worker  * along with this program; if not, see <http://www.gnu.org/licenses>.
18*de1e4e89SAndroid Build Coastguard Worker  */
19*de1e4e89SAndroid Build Coastguard Worker /*
20*de1e4e89SAndroid Build Coastguard Worker  * Authors:
21*de1e4e89SAndroid Build Coastguard Worker  *	Masahide NAKAMURA @USAGI
22*de1e4e89SAndroid Build Coastguard Worker  */
23*de1e4e89SAndroid Build Coastguard Worker 
24*de1e4e89SAndroid Build Coastguard Worker #ifndef __XFRM_H__
25*de1e4e89SAndroid Build Coastguard Worker #define __XFRM_H__ 1
26*de1e4e89SAndroid Build Coastguard Worker 
27*de1e4e89SAndroid Build Coastguard Worker #include <stdio.h>
28*de1e4e89SAndroid Build Coastguard Worker #include <sys/socket.h>
29*de1e4e89SAndroid Build Coastguard Worker #include <linux/in.h>
30*de1e4e89SAndroid Build Coastguard Worker #include <linux/xfrm.h>
31*de1e4e89SAndroid Build Coastguard Worker #include <linux/ipsec.h>
32*de1e4e89SAndroid Build Coastguard Worker 
33*de1e4e89SAndroid Build Coastguard Worker #ifdef __i386__
34*de1e4e89SAndroid Build Coastguard Worker /* b/138147164 */
35*de1e4e89SAndroid Build Coastguard Worker /* Adapted from checks in system/netd/server/XfrmController.h */
36*de1e4e89SAndroid Build Coastguard Worker _Static_assert(sizeof(struct xfrm_usersa_info) - offsetof(struct xfrm_usersa_info, flags) == 8,
37*de1e4e89SAndroid Build Coastguard Worker                "struct xfrm_usersa_info probably misaligned with kernel struct.");
38*de1e4e89SAndroid Build Coastguard Worker _Static_assert(sizeof(struct xfrm_usersa_info) % 8 == 0,
39*de1e4e89SAndroid Build Coastguard Worker                "struct xfrm_usersa_info is not 64-bit aligned.");
40*de1e4e89SAndroid Build Coastguard Worker _Static_assert(sizeof(struct xfrm_userpolicy_info) - offsetof(struct xfrm_userpolicy_info, share) == 5,
41*de1e4e89SAndroid Build Coastguard Worker                "struct xfrm_userpolicy_info probably misaligned with kernel struct.");
42*de1e4e89SAndroid Build Coastguard Worker _Static_assert(sizeof(struct xfrm_userpolicy_info) % 8 == 0,
43*de1e4e89SAndroid Build Coastguard Worker                "struct xfrm_userpolicy_info is not 64-bit aligned.");
44*de1e4e89SAndroid Build Coastguard Worker #endif /* __i386__ */
45*de1e4e89SAndroid Build Coastguard Worker 
46*de1e4e89SAndroid Build Coastguard Worker #ifndef IPPROTO_MH
47*de1e4e89SAndroid Build Coastguard Worker #define IPPROTO_MH              135
48*de1e4e89SAndroid Build Coastguard Worker #endif
49*de1e4e89SAndroid Build Coastguard Worker 
50*de1e4e89SAndroid Build Coastguard Worker #define XFRMS_RTA(x)  ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_usersa_info))))
51*de1e4e89SAndroid Build Coastguard Worker #define XFRMS_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_usersa_info))
52*de1e4e89SAndroid Build Coastguard Worker 
53*de1e4e89SAndroid Build Coastguard Worker #define XFRMP_RTA(x)  ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_userpolicy_info))))
54*de1e4e89SAndroid Build Coastguard Worker #define XFRMP_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_userpoilcy_info))
55*de1e4e89SAndroid Build Coastguard Worker 
56*de1e4e89SAndroid Build Coastguard Worker #define XFRMSID_RTA(x)  ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_usersa_id))))
57*de1e4e89SAndroid Build Coastguard Worker #define XFRMSID_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_usersa_id))
58*de1e4e89SAndroid Build Coastguard Worker 
59*de1e4e89SAndroid Build Coastguard Worker #define XFRMPID_RTA(x)  ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_userpolicy_id))))
60*de1e4e89SAndroid Build Coastguard Worker #define XFRMPID_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_userpoilcy_id))
61*de1e4e89SAndroid Build Coastguard Worker 
62*de1e4e89SAndroid Build Coastguard Worker #define XFRMACQ_RTA(x)	((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_acquire))))
63*de1e4e89SAndroid Build Coastguard Worker #define XFRMEXP_RTA(x)	((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_expire))))
64*de1e4e89SAndroid Build Coastguard Worker #define XFRMPEXP_RTA(x)	((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_polexpire))))
65*de1e4e89SAndroid Build Coastguard Worker 
66*de1e4e89SAndroid Build Coastguard Worker #define XFRMREP_RTA(x)	((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_report))))
67*de1e4e89SAndroid Build Coastguard Worker 
68*de1e4e89SAndroid Build Coastguard Worker #define XFRMSAPD_RTA(x)	((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(__u32))))
69*de1e4e89SAndroid Build Coastguard Worker #define XFRM_FLAG_PRINT(fp, flags, f, s) \
70*de1e4e89SAndroid Build Coastguard Worker 	do { \
71*de1e4e89SAndroid Build Coastguard Worker 		if (flags & f) { \
72*de1e4e89SAndroid Build Coastguard Worker 			flags &= ~f; \
73*de1e4e89SAndroid Build Coastguard Worker 			fprintf(fp, s "%s", (flags ? " " : "")); \
74*de1e4e89SAndroid Build Coastguard Worker 		} \
75*de1e4e89SAndroid Build Coastguard Worker 	} while(0)
76*de1e4e89SAndroid Build Coastguard Worker 
77*de1e4e89SAndroid Build Coastguard Worker struct xfrm_buffer {
78*de1e4e89SAndroid Build Coastguard Worker 	char *buf;
79*de1e4e89SAndroid Build Coastguard Worker 	int size;
80*de1e4e89SAndroid Build Coastguard Worker 	int offset;
81*de1e4e89SAndroid Build Coastguard Worker 
82*de1e4e89SAndroid Build Coastguard Worker 	int nlmsg_count;
83*de1e4e89SAndroid Build Coastguard Worker 	struct rtnl_handle *rth;
84*de1e4e89SAndroid Build Coastguard Worker };
85*de1e4e89SAndroid Build Coastguard Worker 
86*de1e4e89SAndroid Build Coastguard Worker struct xfrm_filter {
87*de1e4e89SAndroid Build Coastguard Worker 	int use;
88*de1e4e89SAndroid Build Coastguard Worker 
89*de1e4e89SAndroid Build Coastguard Worker 	struct xfrm_usersa_info xsinfo;
90*de1e4e89SAndroid Build Coastguard Worker 	__u8 id_src_mask;
91*de1e4e89SAndroid Build Coastguard Worker 	__u8 id_dst_mask;
92*de1e4e89SAndroid Build Coastguard Worker 	__u8 id_proto_mask;
93*de1e4e89SAndroid Build Coastguard Worker 	__u32 id_spi_mask;
94*de1e4e89SAndroid Build Coastguard Worker 	__u8 mode_mask;
95*de1e4e89SAndroid Build Coastguard Worker 	__u32 reqid_mask;
96*de1e4e89SAndroid Build Coastguard Worker 	__u8 state_flags_mask;
97*de1e4e89SAndroid Build Coastguard Worker 
98*de1e4e89SAndroid Build Coastguard Worker 	struct xfrm_userpolicy_info xpinfo;
99*de1e4e89SAndroid Build Coastguard Worker 	__u8 dir_mask;
100*de1e4e89SAndroid Build Coastguard Worker 	__u8 sel_src_mask;
101*de1e4e89SAndroid Build Coastguard Worker 	__u8 sel_dst_mask;
102*de1e4e89SAndroid Build Coastguard Worker 	__u32 sel_dev_mask;
103*de1e4e89SAndroid Build Coastguard Worker 	__u8 upspec_proto_mask;
104*de1e4e89SAndroid Build Coastguard Worker 	__u16 upspec_sport_mask;
105*de1e4e89SAndroid Build Coastguard Worker 	__u16 upspec_dport_mask;
106*de1e4e89SAndroid Build Coastguard Worker 	__u32 index_mask;
107*de1e4e89SAndroid Build Coastguard Worker 	__u8 action_mask;
108*de1e4e89SAndroid Build Coastguard Worker 	__u32 priority_mask;
109*de1e4e89SAndroid Build Coastguard Worker 	__u8 policy_flags_mask;
110*de1e4e89SAndroid Build Coastguard Worker 	__u8 filter_socket;
111*de1e4e89SAndroid Build Coastguard Worker 
112*de1e4e89SAndroid Build Coastguard Worker 	__u8 ptype;
113*de1e4e89SAndroid Build Coastguard Worker 	__u8 ptype_mask;
114*de1e4e89SAndroid Build Coastguard Worker 
115*de1e4e89SAndroid Build Coastguard Worker };
116*de1e4e89SAndroid Build Coastguard Worker #define XFRM_FILTER_MASK_FULL (~0)
117*de1e4e89SAndroid Build Coastguard Worker 
118*de1e4e89SAndroid Build Coastguard Worker extern struct xfrm_filter filter;
119*de1e4e89SAndroid Build Coastguard Worker 
120*de1e4e89SAndroid Build Coastguard Worker int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
121*de1e4e89SAndroid Build Coastguard Worker 		     void *arg);
122*de1e4e89SAndroid Build Coastguard Worker int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
123*de1e4e89SAndroid Build Coastguard Worker 		      void *arg);
124*de1e4e89SAndroid Build Coastguard Worker int do_xfrm_state(int argc, char **argv);
125*de1e4e89SAndroid Build Coastguard Worker int do_xfrm_policy(int argc, char **argv);
126*de1e4e89SAndroid Build Coastguard Worker int do_xfrm_monitor(int argc, char **argv);
127*de1e4e89SAndroid Build Coastguard Worker 
128*de1e4e89SAndroid Build Coastguard Worker int xfrm_addr_match(xfrm_address_t *x1, xfrm_address_t *x2, int bits);
129*de1e4e89SAndroid Build Coastguard Worker int xfrm_xfrmproto_is_ipsec(__u8 proto);
130*de1e4e89SAndroid Build Coastguard Worker int xfrm_xfrmproto_is_ro(__u8 proto);
131*de1e4e89SAndroid Build Coastguard Worker int xfrm_xfrmproto_getbyname(char *name);
132*de1e4e89SAndroid Build Coastguard Worker int xfrm_algotype_getbyname(char *name);
133*de1e4e89SAndroid Build Coastguard Worker int xfrm_parse_mark(struct xfrm_mark *mark, int *argcp, char ***argvp);
134*de1e4e89SAndroid Build Coastguard Worker const char *strxf_xfrmproto(__u8 proto);
135*de1e4e89SAndroid Build Coastguard Worker const char *strxf_algotype(int type);
136*de1e4e89SAndroid Build Coastguard Worker const char *strxf_mask8(__u8 mask);
137*de1e4e89SAndroid Build Coastguard Worker const char *strxf_mask32(__u32 mask);
138*de1e4e89SAndroid Build Coastguard Worker const char *strxf_share(__u8 share);
139*de1e4e89SAndroid Build Coastguard Worker const char *strxf_proto(__u8 proto);
140*de1e4e89SAndroid Build Coastguard Worker const char *strxf_ptype(__u8 ptype);
141*de1e4e89SAndroid Build Coastguard Worker void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id,
142*de1e4e89SAndroid Build Coastguard Worker 			__u8 mode, __u32 reqid, __u16 family, int force_spi,
143*de1e4e89SAndroid Build Coastguard Worker 			FILE *fp, const char *prefix, const char *title);
144*de1e4e89SAndroid Build Coastguard Worker void xfrm_stats_print(struct xfrm_stats *s, FILE *fp, const char *prefix);
145*de1e4e89SAndroid Build Coastguard Worker void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg,
146*de1e4e89SAndroid Build Coastguard Worker 			 struct xfrm_lifetime_cur *cur,
147*de1e4e89SAndroid Build Coastguard Worker 			 FILE *fp, const char *prefix);
148*de1e4e89SAndroid Build Coastguard Worker void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
149*de1e4e89SAndroid Build Coastguard Worker 			 FILE *fp, const char *prefix);
150*de1e4e89SAndroid Build Coastguard Worker void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
151*de1e4e89SAndroid Build Coastguard Worker 		      FILE *fp, const char *prefix);
152*de1e4e89SAndroid Build Coastguard Worker void xfrm_state_info_print(struct xfrm_usersa_info *xsinfo,
153*de1e4e89SAndroid Build Coastguard Worker 			    struct rtattr *tb[], FILE *fp, const char *prefix,
154*de1e4e89SAndroid Build Coastguard Worker 			   const char *title);
155*de1e4e89SAndroid Build Coastguard Worker void xfrm_policy_info_print(struct xfrm_userpolicy_info *xpinfo,
156*de1e4e89SAndroid Build Coastguard Worker 			    struct rtattr *tb[], FILE *fp, const char *prefix,
157*de1e4e89SAndroid Build Coastguard Worker 			    const char *title);
158*de1e4e89SAndroid Build Coastguard Worker int xfrm_id_parse(xfrm_address_t *saddr, struct xfrm_id *id, __u16 *family,
159*de1e4e89SAndroid Build Coastguard Worker 		  int loose, int *argcp, char ***argvp);
160*de1e4e89SAndroid Build Coastguard Worker int xfrm_mode_parse(__u8 *mode, int *argcp, char ***argvp);
161*de1e4e89SAndroid Build Coastguard Worker int xfrm_encap_type_parse(__u16 *type, int *argcp, char ***argvp);
162*de1e4e89SAndroid Build Coastguard Worker int xfrm_reqid_parse(__u32 *reqid, int *argcp, char ***argvp);
163*de1e4e89SAndroid Build Coastguard Worker int xfrm_selector_parse(struct xfrm_selector *sel, int *argcp, char ***argvp);
164*de1e4e89SAndroid Build Coastguard Worker int xfrm_lifetime_cfg_parse(struct xfrm_lifetime_cfg *lft,
165*de1e4e89SAndroid Build Coastguard Worker 			    int *argcp, char ***argvp);
166*de1e4e89SAndroid Build Coastguard Worker int xfrm_sctx_parse(char *ctxstr, char *context,
167*de1e4e89SAndroid Build Coastguard Worker 		    struct xfrm_user_sec_ctx *sctx);
168*de1e4e89SAndroid Build Coastguard Worker #endif
169