net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 1 | /* $USAGI: $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (C)2004 USAGI/WIDE Project |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 5 | * |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 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. |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 10 | * |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 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. |
Stephen Hemminger | ae665a5 | 2006-12-05 10:10:22 -0800 | [diff] [blame] | 15 | * |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 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> |
osdl.net!shemminger | 63d91b4 | 2004-10-20 23:22:30 +0000 | [diff] [blame] | 31 | |
| 32 | #ifndef IPPROTO_SCTP |
| 33 | # define IPPROTO_SCTP 132 |
| 34 | #endif |
shemminger | 27356a5 | 2006-01-12 18:31:36 +0000 | [diff] [blame] | 35 | #ifndef IPPPROTO_DCCP |
| 36 | # define IPPROTO_DCCP 33 |
| 37 | #endif |
Masahide NAKAMURA | 0bf0fbc | 2006-12-05 19:16:12 +0900 | [diff] [blame] | 38 | #ifndef IPPROTO_MH |
| 39 | # define IPPROTO_MH 135 |
| 40 | #endif |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 41 | |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 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 | |
shemminger | 669ae74 | 2005-11-07 18:39:30 +0000 | [diff] [blame] | 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 | |
linux-ipv6.org!nakam | 48f1ef9 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 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 | |
Masahide NAKAMURA | c54f31e | 2006-12-05 19:16:05 +0900 | [diff] [blame] | 58 | #define XFRMREP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_report)))) |
| 59 | |
jamal | 0bb4a4c | 2007-05-03 19:09:41 -0400 | [diff] [blame] | 60 | #define XFRMSAPD_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(__u32)))) |
net[shemminger]!shemminger | eaa34ee | 2005-01-17 23:29:39 +0000 | [diff] [blame] | 61 | #define XFRM_FLAG_PRINT(fp, flags, f, s) \ |
| 62 | do { \ |
| 63 | if (flags & f) { \ |
| 64 | flags &= ~f; \ |
| 65 | fprintf(fp, s "%s", (flags ? " " : "")); \ |
| 66 | } \ |
| 67 | } while(0) |
| 68 | |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 69 | struct xfrm_buffer { |
| 70 | char *buf; |
| 71 | int size; |
| 72 | int offset; |
| 73 | |
| 74 | int nlmsg_count; |
| 75 | struct rtnl_handle *rth; |
| 76 | }; |
| 77 | |
| 78 | struct xfrm_filter { |
| 79 | int use; |
| 80 | |
| 81 | struct xfrm_usersa_info xsinfo; |
net[shemminger]!shemminger | eaa34ee | 2005-01-17 23:29:39 +0000 | [diff] [blame] | 82 | __u8 id_src_mask; |
| 83 | __u8 id_dst_mask; |
| 84 | __u8 id_proto_mask; |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 85 | __u32 id_spi_mask; |
net[shemminger]!shemminger | eaa34ee | 2005-01-17 23:29:39 +0000 | [diff] [blame] | 86 | __u8 mode_mask; |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 87 | __u32 reqid_mask; |
net[shemminger]!shemminger | eaa34ee | 2005-01-17 23:29:39 +0000 | [diff] [blame] | 88 | __u8 state_flags_mask; |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 89 | |
| 90 | struct xfrm_userpolicy_info xpinfo; |
net[shemminger]!shemminger | eaa34ee | 2005-01-17 23:29:39 +0000 | [diff] [blame] | 91 | __u8 dir_mask; |
| 92 | __u8 sel_src_mask; |
| 93 | __u8 sel_dst_mask; |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 94 | __u32 sel_dev_mask; |
net[shemminger]!shemminger | eaa34ee | 2005-01-17 23:29:39 +0000 | [diff] [blame] | 95 | __u8 upspec_proto_mask; |
| 96 | __u16 upspec_sport_mask; |
| 97 | __u16 upspec_dport_mask; |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 98 | __u32 index_mask; |
net[shemminger]!shemminger | eaa34ee | 2005-01-17 23:29:39 +0000 | [diff] [blame] | 99 | __u8 action_mask; |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 100 | __u32 priority_mask; |
Masahide NAKAMURA | c1fa225 | 2007-08-24 11:05:18 +0900 | [diff] [blame] | 101 | __u8 policy_flags_mask; |
Masahide NAKAMURA | 972938e | 2006-12-05 19:15:38 +0900 | [diff] [blame] | 102 | |
| 103 | __u8 ptype; |
| 104 | __u8 ptype_mask; |
| 105 | |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 106 | }; |
net[shemminger]!shemminger | eaa34ee | 2005-01-17 23:29:39 +0000 | [diff] [blame] | 107 | #define XFRM_FILTER_MASK_FULL (~0) |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 108 | |
| 109 | extern struct xfrm_filter filter; |
| 110 | |
linux-ipv6.org!nakam | 48f1ef9 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 111 | int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n, |
| 112 | void *arg); |
| 113 | int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n, |
| 114 | void *arg); |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 115 | int do_xfrm_state(int argc, char **argv); |
| 116 | int do_xfrm_policy(int argc, char **argv); |
linux-ipv6.org!nakam | 48f1ef9 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 117 | int do_xfrm_monitor(int argc, char **argv); |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 118 | |
net[shemminger]!shemminger | eaa34ee | 2005-01-17 23:29:39 +0000 | [diff] [blame] | 119 | int xfrm_addr_match(xfrm_address_t *x1, xfrm_address_t *x2, int bits); |
Masahide NAKAMURA | 7ea4f5d | 2006-12-05 19:15:47 +0900 | [diff] [blame] | 120 | int xfrm_xfrmproto_is_ipsec(__u8 proto); |
| 121 | int xfrm_xfrmproto_is_ro(__u8 proto); |
org[shemminger]!nakam | 29aa4dd | 2004-09-28 18:40:49 +0000 | [diff] [blame] | 122 | int xfrm_xfrmproto_getbyname(char *name); |
net[shemminger]!shemminger | 7809c61 | 2004-08-11 23:41:38 +0000 | [diff] [blame] | 123 | int xfrm_algotype_getbyname(char *name); |
org[shemminger]!nakam | 29aa4dd | 2004-09-28 18:40:49 +0000 | [diff] [blame] | 124 | const char *strxf_xfrmproto(__u8 proto); |
net[shemminger]!shemminger | 7809c61 | 2004-08-11 23:41:38 +0000 | [diff] [blame] | 125 | const char *strxf_algotype(int type); |
net[shemminger]!shemminger | eaa34ee | 2005-01-17 23:29:39 +0000 | [diff] [blame] | 126 | const char *strxf_mask8(__u8 mask); |
| 127 | const char *strxf_mask32(__u32 mask); |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 128 | const char *strxf_share(__u8 share); |
net[shemminger]!shemminger | 30ff508 | 2004-07-30 20:26:15 +0000 | [diff] [blame] | 129 | const char *strxf_proto(__u8 proto); |
Masahide NAKAMURA | efe69c1 | 2007-08-24 11:05:24 +0900 | [diff] [blame] | 130 | const char *strxf_ptype(__u8 ptype); |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 131 | void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id, |
net[shemminger]!shemminger | eaa34ee | 2005-01-17 23:29:39 +0000 | [diff] [blame] | 132 | __u8 mode, __u32 reqid, __u16 family, int force_spi, |
linux-ipv6.org!nakam | 48f1ef9 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 133 | FILE *fp, const char *prefix, const char *title); |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 134 | void xfrm_stats_print(struct xfrm_stats *s, FILE *fp, const char *prefix); |
| 135 | void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg, |
| 136 | struct xfrm_lifetime_cur *cur, |
| 137 | FILE *fp, const char *prefix); |
| 138 | void xfrm_selector_print(struct xfrm_selector *sel, __u16 family, |
| 139 | FILE *fp, const char *prefix); |
7!tgraf | 43d9d2d | 2005-01-18 22:11:58 +0000 | [diff] [blame] | 140 | void xfrm_xfrma_print(struct rtattr *tb[], __u16 family, |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 141 | FILE *fp, const char *prefix); |
linux-ipv6.org!nakam | 48f1ef9 | 2005-03-22 16:13:21 +0000 | [diff] [blame] | 142 | void xfrm_state_info_print(struct xfrm_usersa_info *xsinfo, |
| 143 | struct rtattr *tb[], FILE *fp, const char *prefix, |
| 144 | const char *title); |
| 145 | void xfrm_policy_info_print(struct xfrm_userpolicy_info *xpinfo, |
| 146 | struct rtattr *tb[], FILE *fp, const char *prefix, |
| 147 | const char *title); |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 148 | int xfrm_id_parse(xfrm_address_t *saddr, struct xfrm_id *id, __u16 *family, |
net[shemminger]!shemminger | 7809c61 | 2004-08-11 23:41:38 +0000 | [diff] [blame] | 149 | int loose, int *argcp, char ***argvp); |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 150 | int xfrm_mode_parse(__u8 *mode, int *argcp, char ***argvp); |
osdl.net!shemminger | 5cf576d | 2005-03-10 19:04:00 +0000 | [diff] [blame] | 151 | int xfrm_encap_type_parse(__u16 *type, int *argcp, char ***argvp); |
net[shemminger]!shemminger | c769987 | 2004-07-07 17:05:56 +0000 | [diff] [blame] | 152 | int xfrm_reqid_parse(__u32 *reqid, int *argcp, char ***argvp); |
| 153 | int xfrm_selector_parse(struct xfrm_selector *sel, int *argcp, char ***argvp); |
| 154 | int xfrm_lifetime_cfg_parse(struct xfrm_lifetime_cfg *lft, |
| 155 | int *argcp, char ***argvp); |
| 156 | |
| 157 | #endif |