2023-01-11 10:53:46 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2004-07-08 01:05:56 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C)2004 USAGI/WIDE Project
|
2006-12-06 02:10:22 +08:00
|
|
|
*
|
2004-07-08 01:05:56 +08:00
|
|
|
* Authors:
|
|
|
|
* Masahide NAKAMURA @USAGI
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __XFRM_H__
|
|
|
|
#define __XFRM_H__ 1
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/socket.h>
|
2017-06-15 01:10:05 +08:00
|
|
|
#include <linux/in.h>
|
2004-07-08 01:05:56 +08:00
|
|
|
#include <linux/xfrm.h>
|
2017-06-15 01:10:05 +08:00
|
|
|
#include <linux/ipsec.h>
|
2004-07-08 01:05:56 +08:00
|
|
|
|
2017-11-13 18:21:19 +08:00
|
|
|
#ifndef IPPROTO_MH
|
|
|
|
#define IPPROTO_MH 135
|
|
|
|
#endif
|
|
|
|
|
2004-07-08 01:05:56 +08:00
|
|
|
#define XFRMS_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_usersa_info))))
|
|
|
|
#define XFRMS_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_usersa_info))
|
|
|
|
|
|
|
|
#define XFRMP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_userpolicy_info))))
|
|
|
|
#define XFRMP_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_userpoilcy_info))
|
|
|
|
|
2005-11-08 02:39:30 +08:00
|
|
|
#define XFRMSID_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_usersa_id))))
|
|
|
|
#define XFRMSID_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_usersa_id))
|
|
|
|
|
|
|
|
#define XFRMPID_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_userpolicy_id))))
|
|
|
|
#define XFRMPID_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_userpoilcy_id))
|
|
|
|
|
2005-03-23 00:13:21 +08:00
|
|
|
#define XFRMACQ_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_acquire))))
|
|
|
|
#define XFRMEXP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_expire))))
|
|
|
|
#define XFRMPEXP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_polexpire))))
|
|
|
|
|
2006-12-05 18:16:05 +08:00
|
|
|
#define XFRMREP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_report))))
|
|
|
|
|
2007-05-04 07:09:41 +08:00
|
|
|
#define XFRMSAPD_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(__u32))))
|
2005-01-18 07:29:39 +08:00
|
|
|
#define XFRM_FLAG_PRINT(fp, flags, f, s) \
|
|
|
|
do { \
|
|
|
|
if (flags & f) { \
|
|
|
|
flags &= ~f; \
|
|
|
|
fprintf(fp, s "%s", (flags ? " " : "")); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
2004-07-08 01:05:56 +08:00
|
|
|
struct xfrm_buffer {
|
|
|
|
char *buf;
|
|
|
|
int size;
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
int nlmsg_count;
|
|
|
|
struct rtnl_handle *rth;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct xfrm_filter {
|
|
|
|
int use;
|
|
|
|
|
|
|
|
struct xfrm_usersa_info xsinfo;
|
2005-01-18 07:29:39 +08:00
|
|
|
__u8 id_src_mask;
|
|
|
|
__u8 id_dst_mask;
|
|
|
|
__u8 id_proto_mask;
|
2004-07-08 01:05:56 +08:00
|
|
|
__u32 id_spi_mask;
|
2005-01-18 07:29:39 +08:00
|
|
|
__u8 mode_mask;
|
2004-07-08 01:05:56 +08:00
|
|
|
__u32 reqid_mask;
|
2005-01-18 07:29:39 +08:00
|
|
|
__u8 state_flags_mask;
|
2004-07-08 01:05:56 +08:00
|
|
|
|
|
|
|
struct xfrm_userpolicy_info xpinfo;
|
2005-01-18 07:29:39 +08:00
|
|
|
__u8 dir_mask;
|
|
|
|
__u8 sel_src_mask;
|
|
|
|
__u8 sel_dst_mask;
|
2004-07-08 01:05:56 +08:00
|
|
|
__u32 sel_dev_mask;
|
2005-01-18 07:29:39 +08:00
|
|
|
__u8 upspec_proto_mask;
|
|
|
|
__u16 upspec_sport_mask;
|
|
|
|
__u16 upspec_dport_mask;
|
2004-07-08 01:05:56 +08:00
|
|
|
__u32 index_mask;
|
2005-01-18 07:29:39 +08:00
|
|
|
__u8 action_mask;
|
2004-07-08 01:05:56 +08:00
|
|
|
__u32 priority_mask;
|
2007-08-24 10:05:18 +08:00
|
|
|
__u8 policy_flags_mask;
|
2017-10-31 02:11:44 +08:00
|
|
|
__u8 filter_socket;
|
2006-12-05 18:15:38 +08:00
|
|
|
|
|
|
|
__u8 ptype;
|
|
|
|
__u8 ptype_mask;
|
|
|
|
|
2004-07-08 01:05:56 +08:00
|
|
|
};
|
2005-01-18 07:29:39 +08:00
|
|
|
#define XFRM_FILTER_MASK_FULL (~0)
|
2004-07-08 01:05:56 +08:00
|
|
|
|
|
|
|
extern struct xfrm_filter filter;
|
|
|
|
|
2018-10-20 04:42:36 +08:00
|
|
|
int xfrm_state_print(struct nlmsghdr *n, void *arg);
|
|
|
|
int xfrm_policy_print(struct nlmsghdr *n, void *arg);
|
2004-07-08 01:05:56 +08:00
|
|
|
int do_xfrm_state(int argc, char **argv);
|
|
|
|
int do_xfrm_policy(int argc, char **argv);
|
2005-03-23 00:13:21 +08:00
|
|
|
int do_xfrm_monitor(int argc, char **argv);
|
2004-07-08 01:05:56 +08:00
|
|
|
|
2005-01-18 07:29:39 +08:00
|
|
|
int xfrm_addr_match(xfrm_address_t *x1, xfrm_address_t *x2, int bits);
|
2006-12-05 18:15:47 +08:00
|
|
|
int xfrm_xfrmproto_is_ipsec(__u8 proto);
|
|
|
|
int xfrm_xfrmproto_is_ro(__u8 proto);
|
2004-09-29 02:40:49 +08:00
|
|
|
int xfrm_xfrmproto_getbyname(char *name);
|
2004-08-12 07:41:38 +08:00
|
|
|
int xfrm_algotype_getbyname(char *name);
|
2010-02-23 11:15:10 +08:00
|
|
|
int xfrm_parse_mark(struct xfrm_mark *mark, int *argcp, char ***argvp);
|
2004-09-29 02:40:49 +08:00
|
|
|
const char *strxf_xfrmproto(__u8 proto);
|
2004-08-12 07:41:38 +08:00
|
|
|
const char *strxf_algotype(int type);
|
2005-01-18 07:29:39 +08:00
|
|
|
const char *strxf_mask32(__u32 mask);
|
2004-07-31 04:26:15 +08:00
|
|
|
const char *strxf_proto(__u8 proto);
|
2007-08-24 10:05:24 +08:00
|
|
|
const char *strxf_ptype(__u8 ptype);
|
2004-07-08 01:05:56 +08:00
|
|
|
void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
|
|
|
|
FILE *fp, const char *prefix);
|
2022-12-12 15:54:06 +08:00
|
|
|
void xfrm_xfrma_print(struct rtattr *tb[], __u16 family, FILE *fp,
|
|
|
|
const char *prefix, bool nokeys, bool dir);
|
2005-03-23 00:13:21 +08:00
|
|
|
void xfrm_state_info_print(struct xfrm_usersa_info *xsinfo,
|
|
|
|
struct rtattr *tb[], FILE *fp, const char *prefix,
|
2019-01-19 03:12:17 +08:00
|
|
|
const char *title, bool nokeys);
|
2005-03-23 00:13:21 +08:00
|
|
|
void xfrm_policy_info_print(struct xfrm_userpolicy_info *xpinfo,
|
|
|
|
struct rtattr *tb[], FILE *fp, const char *prefix,
|
|
|
|
const char *title);
|
2021-10-25 16:17:06 +08:00
|
|
|
int xfrm_policy_default_print(struct nlmsghdr *n, FILE *fp);
|
2004-07-08 01:05:56 +08:00
|
|
|
int xfrm_id_parse(xfrm_address_t *saddr, struct xfrm_id *id, __u16 *family,
|
2004-08-12 07:41:38 +08:00
|
|
|
int loose, int *argcp, char ***argvp);
|
2004-07-08 01:05:56 +08:00
|
|
|
int xfrm_mode_parse(__u8 *mode, int *argcp, char ***argvp);
|
2005-03-11 03:04:00 +08:00
|
|
|
int xfrm_encap_type_parse(__u16 *type, int *argcp, char ***argvp);
|
2004-07-08 01:05:56 +08:00
|
|
|
int xfrm_reqid_parse(__u32 *reqid, int *argcp, char ***argvp);
|
|
|
|
int xfrm_selector_parse(struct xfrm_selector *sel, int *argcp, char ***argvp);
|
|
|
|
int xfrm_lifetime_cfg_parse(struct xfrm_lifetime_cfg *lft,
|
|
|
|
int *argcp, char ***argvp);
|
2011-02-03 07:31:39 +08:00
|
|
|
int xfrm_sctx_parse(char *ctxstr, char *context,
|
|
|
|
struct xfrm_user_sec_ctx *sctx);
|
2004-07-08 01:05:56 +08:00
|
|
|
#endif
|