]> git.proxmox.com Git - mirror_iproute2.git/blame - ip/xfrm.h
XFRM: sub policy support.
[mirror_iproute2.git] / ip / xfrm.h
CommitLineData
c7699875 1/* $USAGI: $ */
2
3/*
4 * Copyright (C)2004 USAGI/WIDE Project
5 *
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.
10 *
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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20/*
21 * Authors:
22 * Masahide NAKAMURA @USAGI
23 */
24
25#ifndef __XFRM_H__
26#define __XFRM_H__ 1
27
28#include <stdio.h>
29#include <sys/socket.h>
30#include <linux/xfrm.h>
63d91b4f
SH
31
32#ifndef IPPROTO_SCTP
33# define IPPROTO_SCTP 132
34#endif
27356a5e
SH
35#ifndef IPPPROTO_DCCP
36# define IPPROTO_DCCP 33
37#endif
c7699875 38
c7699875 39#define XFRMS_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_usersa_info))))
40#define XFRMS_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_usersa_info))
41
42#define XFRMP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_userpolicy_info))))
43#define XFRMP_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_userpoilcy_info))
44
669ae748
SH
45#define XFRMSID_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_usersa_id))))
46#define XFRMSID_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_usersa_id))
47
48#define XFRMPID_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_userpolicy_id))))
49#define XFRMPID_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_userpoilcy_id))
50
48f1ef9f 51#define XFRMACQ_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_acquire))))
52#define XFRMEXP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_expire))))
53#define XFRMPEXP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_polexpire))))
54
eaa34ee3 55#define XFRM_FLAG_PRINT(fp, flags, f, s) \
56 do { \
57 if (flags & f) { \
58 flags &= ~f; \
59 fprintf(fp, s "%s", (flags ? " " : "")); \
60 } \
61 } while(0)
62
c7699875 63struct xfrm_buffer {
64 char *buf;
65 int size;
66 int offset;
67
68 int nlmsg_count;
69 struct rtnl_handle *rth;
70};
71
72struct xfrm_filter {
73 int use;
74
75 struct xfrm_usersa_info xsinfo;
eaa34ee3 76 __u8 id_src_mask;
77 __u8 id_dst_mask;
78 __u8 id_proto_mask;
c7699875 79 __u32 id_spi_mask;
eaa34ee3 80 __u8 mode_mask;
c7699875 81 __u32 reqid_mask;
eaa34ee3 82 __u8 state_flags_mask;
c7699875 83
84 struct xfrm_userpolicy_info xpinfo;
eaa34ee3 85 __u8 dir_mask;
86 __u8 sel_src_mask;
87 __u8 sel_dst_mask;
c7699875 88 __u32 sel_dev_mask;
eaa34ee3 89 __u8 upspec_proto_mask;
90 __u16 upspec_sport_mask;
91 __u16 upspec_dport_mask;
c7699875 92 __u32 index_mask;
eaa34ee3 93 __u8 action_mask;
c7699875 94 __u32 priority_mask;
972938e9
MN
95
96 __u8 ptype;
97 __u8 ptype_mask;
98
c7699875 99};
eaa34ee3 100#define XFRM_FILTER_MASK_FULL (~0)
c7699875 101
102extern struct xfrm_filter filter;
103
48f1ef9f 104int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
105 void *arg);
106int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
107 void *arg);
c7699875 108int do_xfrm_state(int argc, char **argv);
109int do_xfrm_policy(int argc, char **argv);
48f1ef9f 110int do_xfrm_monitor(int argc, char **argv);
c7699875 111
eaa34ee3 112int xfrm_addr_match(xfrm_address_t *x1, xfrm_address_t *x2, int bits);
29aa4dd7 113int xfrm_xfrmproto_getbyname(char *name);
7809c616 114int xfrm_algotype_getbyname(char *name);
29aa4dd7 115const char *strxf_xfrmproto(__u8 proto);
7809c616 116const char *strxf_algotype(int type);
eaa34ee3 117const char *strxf_mask8(__u8 mask);
118const char *strxf_mask32(__u32 mask);
c7699875 119const char *strxf_share(__u8 share);
30ff5089 120const char *strxf_proto(__u8 proto);
c7699875 121void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id,
eaa34ee3 122 __u8 mode, __u32 reqid, __u16 family, int force_spi,
48f1ef9f 123 FILE *fp, const char *prefix, const char *title);
c7699875 124void xfrm_stats_print(struct xfrm_stats *s, FILE *fp, const char *prefix);
125void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg,
126 struct xfrm_lifetime_cur *cur,
127 FILE *fp, const char *prefix);
128void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
129 FILE *fp, const char *prefix);
43d9d2de 130void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
c7699875 131 FILE *fp, const char *prefix);
48f1ef9f 132void xfrm_state_info_print(struct xfrm_usersa_info *xsinfo,
133 struct rtattr *tb[], FILE *fp, const char *prefix,
134 const char *title);
135void xfrm_policy_info_print(struct xfrm_userpolicy_info *xpinfo,
136 struct rtattr *tb[], FILE *fp, const char *prefix,
137 const char *title);
c7699875 138int xfrm_id_parse(xfrm_address_t *saddr, struct xfrm_id *id, __u16 *family,
7809c616 139 int loose, int *argcp, char ***argvp);
c7699875 140int xfrm_mode_parse(__u8 *mode, int *argcp, char ***argvp);
5cf576d9 141int xfrm_encap_type_parse(__u16 *type, int *argcp, char ***argvp);
c7699875 142int xfrm_reqid_parse(__u32 *reqid, int *argcp, char ***argvp);
143int xfrm_selector_parse(struct xfrm_selector *sel, int *argcp, char ***argvp);
144int xfrm_lifetime_cfg_parse(struct xfrm_lifetime_cfg *lft,
145 int *argcp, char ***argvp);
146
147#endif