]> git.proxmox.com Git - mirror_iproute2.git/blame - ip/xfrm.h
Merge branch 'main' into next
[mirror_iproute2.git] / ip / xfrm.h
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
4d98ab00 17 * along with this program; if not, see <http://www.gnu.org/licenses>.
c7699875 18 */
19/*
20 * Authors:
21 * Masahide NAKAMURA @USAGI
22 */
23
24#ifndef __XFRM_H__
25#define __XFRM_H__ 1
26
27#include <stdio.h>
28#include <sys/socket.h>
a9ae195a 29#include <linux/in.h>
c7699875 30#include <linux/xfrm.h>
a9ae195a 31#include <linux/ipsec.h>
c7699875 32
aba736dc
LR
33#ifndef IPPROTO_MH
34#define IPPROTO_MH 135
35#endif
36
c7699875 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))
39
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))
42
669ae748
SH
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))
45
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))
48
48f1ef9f 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))))
52
c54f31ee
MN
53#define XFRMREP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_report))))
54
0bb4a4c2 55#define XFRMSAPD_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(__u32))))
eaa34ee3 56#define XFRM_FLAG_PRINT(fp, flags, f, s) \
57 do { \
58 if (flags & f) { \
59 flags &= ~f; \
60 fprintf(fp, s "%s", (flags ? " " : "")); \
61 } \
62 } while(0)
63
c7699875 64struct xfrm_buffer {
65 char *buf;
66 int size;
67 int offset;
68
69 int nlmsg_count;
70 struct rtnl_handle *rth;
71};
72
73struct xfrm_filter {
74 int use;
75
76 struct xfrm_usersa_info xsinfo;
eaa34ee3 77 __u8 id_src_mask;
78 __u8 id_dst_mask;
79 __u8 id_proto_mask;
c7699875 80 __u32 id_spi_mask;
eaa34ee3 81 __u8 mode_mask;
c7699875 82 __u32 reqid_mask;
eaa34ee3 83 __u8 state_flags_mask;
c7699875 84
85 struct xfrm_userpolicy_info xpinfo;
eaa34ee3 86 __u8 dir_mask;
87 __u8 sel_src_mask;
88 __u8 sel_dst_mask;
c7699875 89 __u32 sel_dev_mask;
eaa34ee3 90 __u8 upspec_proto_mask;
91 __u16 upspec_sport_mask;
92 __u16 upspec_dport_mask;
c7699875 93 __u32 index_mask;
eaa34ee3 94 __u8 action_mask;
c7699875 95 __u32 priority_mask;
c1fa2253 96 __u8 policy_flags_mask;
20e4840a 97 __u8 filter_socket;
972938e9
MN
98
99 __u8 ptype;
100 __u8 ptype_mask;
101
c7699875 102};
eaa34ee3 103#define XFRM_FILTER_MASK_FULL (~0)
c7699875 104
105extern struct xfrm_filter filter;
106
cd554f2c 107int xfrm_state_print(struct nlmsghdr *n, void *arg);
a6af9f2e 108int xfrm_state_print_nokeys(struct nlmsghdr *n, void *arg);
cd554f2c 109int xfrm_policy_print(struct nlmsghdr *n, void *arg);
c7699875 110int do_xfrm_state(int argc, char **argv);
111int do_xfrm_policy(int argc, char **argv);
48f1ef9f 112int do_xfrm_monitor(int argc, char **argv);
c7699875 113
eaa34ee3 114int xfrm_addr_match(xfrm_address_t *x1, xfrm_address_t *x2, int bits);
7ea4f5d3
MN
115int xfrm_xfrmproto_is_ipsec(__u8 proto);
116int xfrm_xfrmproto_is_ro(__u8 proto);
29aa4dd7 117int xfrm_xfrmproto_getbyname(char *name);
7809c616 118int xfrm_algotype_getbyname(char *name);
f6fd52e6 119int xfrm_parse_mark(struct xfrm_mark *mark, int *argcp, char ***argvp);
29aa4dd7 120const char *strxf_xfrmproto(__u8 proto);
7809c616 121const char *strxf_algotype(int type);
eaa34ee3 122const char *strxf_mask32(__u32 mask);
30ff5089 123const char *strxf_proto(__u8 proto);
efe69c1b 124const char *strxf_ptype(__u8 ptype);
c7699875 125void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
126 FILE *fp, const char *prefix);
43d9d2de 127void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
a6af9f2e 128 FILE *fp, const char *prefix, bool nokeys);
48f1ef9f 129void xfrm_state_info_print(struct xfrm_usersa_info *xsinfo,
130 struct rtattr *tb[], FILE *fp, const char *prefix,
a6af9f2e 131 const char *title, bool nokeys);
48f1ef9f 132void xfrm_policy_info_print(struct xfrm_userpolicy_info *xpinfo,
133 struct rtattr *tb[], FILE *fp, const char *prefix,
134 const char *title);
c7699875 135int xfrm_id_parse(xfrm_address_t *saddr, struct xfrm_id *id, __u16 *family,
7809c616 136 int loose, int *argcp, char ***argvp);
c7699875 137int xfrm_mode_parse(__u8 *mode, int *argcp, char ***argvp);
5cf576d9 138int xfrm_encap_type_parse(__u16 *type, int *argcp, char ***argvp);
c7699875 139int xfrm_reqid_parse(__u32 *reqid, int *argcp, char ***argvp);
140int xfrm_selector_parse(struct xfrm_selector *sel, int *argcp, char ***argvp);
141int xfrm_lifetime_cfg_parse(struct xfrm_lifetime_cfg *lft,
142 int *argcp, char ***argvp);
2c319e1a
JL
143int xfrm_sctx_parse(char *ctxstr, char *context,
144 struct xfrm_user_sec_ctx *sctx);
c7699875 145#endif