]>
Commit | Line | Data |
---|---|---|
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 |
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 | |
0bf0fbc4 MN |
38 | #ifndef IPPROTO_MH |
39 | # define IPPROTO_MH 135 | |
40 | #endif | |
c7699875 | 41 | |
c7699875 | 42 | #define XFRMS_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_usersa_info)))) |
43 | #define XFRMS_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_usersa_info)) | |
44 | ||
45 | #define XFRMP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_userpolicy_info)))) | |
46 | #define XFRMP_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_userpoilcy_info)) | |
47 | ||
669ae748 SH |
48 | #define XFRMSID_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_usersa_id)))) |
49 | #define XFRMSID_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_usersa_id)) | |
50 | ||
51 | #define XFRMPID_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_userpolicy_id)))) | |
52 | #define XFRMPID_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_userpoilcy_id)) | |
53 | ||
48f1ef9f | 54 | #define XFRMACQ_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_acquire)))) |
55 | #define XFRMEXP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_expire)))) | |
56 | #define XFRMPEXP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_polexpire)))) | |
57 | ||
c54f31ee MN |
58 | #define XFRMREP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_report)))) |
59 | ||
eaa34ee3 | 60 | #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 | ||
c7699875 | 68 | struct xfrm_buffer { |
69 | char *buf; | |
70 | int size; | |
71 | int offset; | |
72 | ||
73 | int nlmsg_count; | |
74 | struct rtnl_handle *rth; | |
75 | }; | |
76 | ||
77 | struct xfrm_filter { | |
78 | int use; | |
79 | ||
80 | struct xfrm_usersa_info xsinfo; | |
eaa34ee3 | 81 | __u8 id_src_mask; |
82 | __u8 id_dst_mask; | |
83 | __u8 id_proto_mask; | |
c7699875 | 84 | __u32 id_spi_mask; |
eaa34ee3 | 85 | __u8 mode_mask; |
c7699875 | 86 | __u32 reqid_mask; |
eaa34ee3 | 87 | __u8 state_flags_mask; |
c7699875 | 88 | |
89 | struct xfrm_userpolicy_info xpinfo; | |
eaa34ee3 | 90 | __u8 dir_mask; |
91 | __u8 sel_src_mask; | |
92 | __u8 sel_dst_mask; | |
c7699875 | 93 | __u32 sel_dev_mask; |
eaa34ee3 | 94 | __u8 upspec_proto_mask; |
95 | __u16 upspec_sport_mask; | |
96 | __u16 upspec_dport_mask; | |
c7699875 | 97 | __u32 index_mask; |
eaa34ee3 | 98 | __u8 action_mask; |
c7699875 | 99 | __u32 priority_mask; |
972938e9 MN |
100 | |
101 | __u8 ptype; | |
102 | __u8 ptype_mask; | |
103 | ||
c7699875 | 104 | }; |
eaa34ee3 | 105 | #define XFRM_FILTER_MASK_FULL (~0) |
c7699875 | 106 | |
107 | extern struct xfrm_filter filter; | |
108 | ||
48f1ef9f | 109 | int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n, |
110 | void *arg); | |
111 | int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n, | |
112 | void *arg); | |
c7699875 | 113 | int do_xfrm_state(int argc, char **argv); |
114 | int do_xfrm_policy(int argc, char **argv); | |
48f1ef9f | 115 | int do_xfrm_monitor(int argc, char **argv); |
c7699875 | 116 | |
eaa34ee3 | 117 | int xfrm_addr_match(xfrm_address_t *x1, xfrm_address_t *x2, int bits); |
7ea4f5d3 MN |
118 | int xfrm_xfrmproto_is_ipsec(__u8 proto); |
119 | int xfrm_xfrmproto_is_ro(__u8 proto); | |
29aa4dd7 | 120 | int xfrm_xfrmproto_getbyname(char *name); |
7809c616 | 121 | int xfrm_algotype_getbyname(char *name); |
29aa4dd7 | 122 | const char *strxf_xfrmproto(__u8 proto); |
7809c616 | 123 | const char *strxf_algotype(int type); |
eaa34ee3 | 124 | const char *strxf_mask8(__u8 mask); |
125 | const char *strxf_mask32(__u32 mask); | |
c7699875 | 126 | const char *strxf_share(__u8 share); |
30ff5089 | 127 | const char *strxf_proto(__u8 proto); |
c7699875 | 128 | void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id, |
eaa34ee3 | 129 | __u8 mode, __u32 reqid, __u16 family, int force_spi, |
48f1ef9f | 130 | FILE *fp, const char *prefix, const char *title); |
c7699875 | 131 | void xfrm_stats_print(struct xfrm_stats *s, FILE *fp, const char *prefix); |
132 | void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg, | |
133 | struct xfrm_lifetime_cur *cur, | |
134 | FILE *fp, const char *prefix); | |
135 | void xfrm_selector_print(struct xfrm_selector *sel, __u16 family, | |
136 | FILE *fp, const char *prefix); | |
43d9d2de | 137 | void xfrm_xfrma_print(struct rtattr *tb[], __u16 family, |
c7699875 | 138 | FILE *fp, const char *prefix); |
48f1ef9f | 139 | void xfrm_state_info_print(struct xfrm_usersa_info *xsinfo, |
140 | struct rtattr *tb[], FILE *fp, const char *prefix, | |
141 | const char *title); | |
142 | void xfrm_policy_info_print(struct xfrm_userpolicy_info *xpinfo, | |
143 | struct rtattr *tb[], FILE *fp, const char *prefix, | |
144 | const char *title); | |
c7699875 | 145 | int xfrm_id_parse(xfrm_address_t *saddr, struct xfrm_id *id, __u16 *family, |
7809c616 | 146 | int loose, int *argcp, char ***argvp); |
c7699875 | 147 | int xfrm_mode_parse(__u8 *mode, int *argcp, char ***argvp); |
5cf576d9 | 148 | int xfrm_encap_type_parse(__u16 *type, int *argcp, char ***argvp); |
c7699875 | 149 | int xfrm_reqid_parse(__u32 *reqid, int *argcp, char ***argvp); |
150 | int xfrm_selector_parse(struct xfrm_selector *sel, int *argcp, char ***argvp); | |
151 | int xfrm_lifetime_cfg_parse(struct xfrm_lifetime_cfg *lft, | |
152 | int *argcp, char ***argvp); | |
153 | ||
154 | #endif |