blob: 773c92e99e9ef8e36c00578df4e8c4bf5354560c [file] [log] [blame]
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +00001/* $USAGI: $ */
2
3/*
4 * Copyright (C)2004 USAGI/WIDE Project
Stephen Hemmingerae665a52006-12-05 10:10:22 -08005 *
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +00006 * 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.
Stephen Hemmingerae665a52006-12-05 10:10:22 -080010 *
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +000011 * 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.
Stephen Hemmingerae665a52006-12-05 10:10:22 -080015 *
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +000016 * You should have received a copy of the GNU General Public License
Stephen Hemminger4d98ab02013-12-06 15:05:07 -080017 * along with this program; if not, see <http://www.gnu.org/licenses>.
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +000018 */
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>
29#include <linux/xfrm.h>
osdl.net!shemminger63d91b42004-10-20 23:22:30 +000030
31#ifndef IPPROTO_SCTP
32# define IPPROTO_SCTP 132
33#endif
Stephen Hemmingerc1cdf2d2009-08-06 14:38:18 -070034#ifndef IPPROTO_DCCP
shemminger27356a52006-01-12 18:31:36 +000035# define IPPROTO_DCCP 33
36#endif
Masahide NAKAMURA0bf0fbc2006-12-05 19:16:12 +090037#ifndef IPPROTO_MH
38# define IPPROTO_MH 135
39#endif
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +000040
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +000041#define XFRMS_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_usersa_info))))
42#define XFRMS_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_usersa_info))
43
44#define XFRMP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_userpolicy_info))))
45#define XFRMP_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_userpoilcy_info))
46
shemminger669ae742005-11-07 18:39:30 +000047#define XFRMSID_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_usersa_id))))
48#define XFRMSID_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_usersa_id))
49
50#define XFRMPID_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_userpolicy_id))))
51#define XFRMPID_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_userpoilcy_id))
52
linux-ipv6.org!nakam48f1ef92005-03-22 16:13:21 +000053#define XFRMACQ_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_acquire))))
54#define XFRMEXP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_expire))))
55#define XFRMPEXP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_polexpire))))
56
Masahide NAKAMURAc54f31e2006-12-05 19:16:05 +090057#define XFRMREP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_report))))
58
jamal0bb4a4c2007-05-03 19:09:41 -040059#define XFRMSAPD_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(__u32))))
net[shemminger]!shemmingereaa34ee2005-01-17 23:29:39 +000060#define XFRM_FLAG_PRINT(fp, flags, f, s) \
61 do { \
62 if (flags & f) { \
63 flags &= ~f; \
64 fprintf(fp, s "%s", (flags ? " " : "")); \
65 } \
66 } while(0)
67
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +000068struct xfrm_buffer {
69 char *buf;
70 int size;
71 int offset;
72
73 int nlmsg_count;
74 struct rtnl_handle *rth;
75};
76
77struct xfrm_filter {
78 int use;
79
80 struct xfrm_usersa_info xsinfo;
net[shemminger]!shemmingereaa34ee2005-01-17 23:29:39 +000081 __u8 id_src_mask;
82 __u8 id_dst_mask;
83 __u8 id_proto_mask;
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +000084 __u32 id_spi_mask;
net[shemminger]!shemmingereaa34ee2005-01-17 23:29:39 +000085 __u8 mode_mask;
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +000086 __u32 reqid_mask;
net[shemminger]!shemmingereaa34ee2005-01-17 23:29:39 +000087 __u8 state_flags_mask;
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +000088
89 struct xfrm_userpolicy_info xpinfo;
net[shemminger]!shemmingereaa34ee2005-01-17 23:29:39 +000090 __u8 dir_mask;
91 __u8 sel_src_mask;
92 __u8 sel_dst_mask;
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +000093 __u32 sel_dev_mask;
net[shemminger]!shemmingereaa34ee2005-01-17 23:29:39 +000094 __u8 upspec_proto_mask;
95 __u16 upspec_sport_mask;
96 __u16 upspec_dport_mask;
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +000097 __u32 index_mask;
net[shemminger]!shemmingereaa34ee2005-01-17 23:29:39 +000098 __u8 action_mask;
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +000099 __u32 priority_mask;
Masahide NAKAMURAc1fa2252007-08-24 11:05:18 +0900100 __u8 policy_flags_mask;
Masahide NAKAMURA972938e2006-12-05 19:15:38 +0900101
102 __u8 ptype;
103 __u8 ptype_mask;
104
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +0000105};
net[shemminger]!shemmingereaa34ee2005-01-17 23:29:39 +0000106#define XFRM_FILTER_MASK_FULL (~0)
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +0000107
108extern struct xfrm_filter filter;
109
linux-ipv6.org!nakam48f1ef92005-03-22 16:13:21 +0000110int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
111 void *arg);
112int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
113 void *arg);
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +0000114int do_xfrm_state(int argc, char **argv);
115int do_xfrm_policy(int argc, char **argv);
linux-ipv6.org!nakam48f1ef92005-03-22 16:13:21 +0000116int do_xfrm_monitor(int argc, char **argv);
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +0000117
net[shemminger]!shemmingereaa34ee2005-01-17 23:29:39 +0000118int xfrm_addr_match(xfrm_address_t *x1, xfrm_address_t *x2, int bits);
Masahide NAKAMURA7ea4f5d2006-12-05 19:15:47 +0900119int xfrm_xfrmproto_is_ipsec(__u8 proto);
120int xfrm_xfrmproto_is_ro(__u8 proto);
org[shemminger]!nakam29aa4dd2004-09-28 18:40:49 +0000121int xfrm_xfrmproto_getbyname(char *name);
net[shemminger]!shemminger7809c612004-08-11 23:41:38 +0000122int xfrm_algotype_getbyname(char *name);
Jamal Hadi Salimf6fd52e2010-02-23 03:15:10 +0000123int xfrm_parse_mark(struct xfrm_mark *mark, int *argcp, char ***argvp);
org[shemminger]!nakam29aa4dd2004-09-28 18:40:49 +0000124const char *strxf_xfrmproto(__u8 proto);
net[shemminger]!shemminger7809c612004-08-11 23:41:38 +0000125const char *strxf_algotype(int type);
net[shemminger]!shemmingereaa34ee2005-01-17 23:29:39 +0000126const char *strxf_mask8(__u8 mask);
127const char *strxf_mask32(__u32 mask);
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +0000128const char *strxf_share(__u8 share);
net[shemminger]!shemminger30ff5082004-07-30 20:26:15 +0000129const char *strxf_proto(__u8 proto);
Masahide NAKAMURAefe69c12007-08-24 11:05:24 +0900130const char *strxf_ptype(__u8 ptype);
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +0000131void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id,
net[shemminger]!shemmingereaa34ee2005-01-17 23:29:39 +0000132 __u8 mode, __u32 reqid, __u16 family, int force_spi,
linux-ipv6.org!nakam48f1ef92005-03-22 16:13:21 +0000133 FILE *fp, const char *prefix, const char *title);
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +0000134void xfrm_stats_print(struct xfrm_stats *s, FILE *fp, const char *prefix);
135void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg,
136 struct xfrm_lifetime_cur *cur,
137 FILE *fp, const char *prefix);
138void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
139 FILE *fp, const char *prefix);
7!tgraf43d9d2d2005-01-18 22:11:58 +0000140void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +0000141 FILE *fp, const char *prefix);
linux-ipv6.org!nakam48f1ef92005-03-22 16:13:21 +0000142void xfrm_state_info_print(struct xfrm_usersa_info *xsinfo,
143 struct rtattr *tb[], FILE *fp, const char *prefix,
144 const char *title);
145void xfrm_policy_info_print(struct xfrm_userpolicy_info *xpinfo,
146 struct rtattr *tb[], FILE *fp, const char *prefix,
147 const char *title);
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +0000148int xfrm_id_parse(xfrm_address_t *saddr, struct xfrm_id *id, __u16 *family,
net[shemminger]!shemminger7809c612004-08-11 23:41:38 +0000149 int loose, int *argcp, char ***argvp);
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +0000150int xfrm_mode_parse(__u8 *mode, int *argcp, char ***argvp);
osdl.net!shemminger5cf576d2005-03-10 19:04:00 +0000151int xfrm_encap_type_parse(__u16 *type, int *argcp, char ***argvp);
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +0000152int xfrm_reqid_parse(__u32 *reqid, int *argcp, char ***argvp);
153int xfrm_selector_parse(struct xfrm_selector *sel, int *argcp, char ***argvp);
154int xfrm_lifetime_cfg_parse(struct xfrm_lifetime_cfg *lft,
155 int *argcp, char ***argvp);
Joy Latten2c319e12011-02-02 17:31:39 -0600156int xfrm_sctx_parse(char *ctxstr, char *context,
157 struct xfrm_user_sec_ctx *sctx);
net[shemminger]!shemmingerc7699872004-07-07 17:05:56 +0000158#endif