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> 31 32#ifndef IPPROTO_SCTP 33# define IPPROTO_SCTP 132 34#endif 35 36#define XFRMS_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_usersa_info)))) 37#define XFRMS_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_usersa_info)) 38 39#define XFRMP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_userpolicy_info)))) 40#define XFRMP_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct xfrm_userpoilcy_info)) 41 42#define XFRMACQ_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_acquire)))) 43#define XFRMEXP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_expire)))) 44#define XFRMPEXP_RTA(x) ((struct rtattr*)(((char*)(x)) + NLMSG_ALIGN(sizeof(struct xfrm_user_polexpire)))) 45 46#define XFRM_FLAG_PRINT(fp, flags, f, s) \ 47 do { \ 48 if (flags & f) { \ 49 flags &= ~f; \ 50 fprintf(fp, s "%s", (flags ? " " : "")); \ 51 } \ 52 } while(0) 53 54struct xfrm_buffer { 55 char *buf; 56 int size; 57 int offset; 58 59 int nlmsg_count; 60 struct rtnl_handle *rth; 61}; 62 63struct xfrm_filter { 64 int use; 65 66 struct xfrm_usersa_info xsinfo; 67 __u8 id_src_mask; 68 __u8 id_dst_mask; 69 __u8 id_proto_mask; 70 __u32 id_spi_mask; 71 __u8 mode_mask; 72 __u32 reqid_mask; 73 __u8 state_flags_mask; 74 75 struct xfrm_userpolicy_info xpinfo; 76 __u8 dir_mask; 77 __u8 sel_src_mask; 78 __u8 sel_dst_mask; 79 __u32 sel_dev_mask; 80 __u8 upspec_proto_mask; 81 __u16 upspec_sport_mask; 82 __u16 upspec_dport_mask; 83 __u32 index_mask; 84 __u8 action_mask; 85 __u32 priority_mask; 86}; 87#define XFRM_FILTER_MASK_FULL (~0) 88 89extern struct xfrm_filter filter; 90 91int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n, 92 void *arg); 93int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n, 94 void *arg); 95int do_xfrm_state(int argc, char **argv); 96int do_xfrm_policy(int argc, char **argv); 97int do_xfrm_monitor(int argc, char **argv); 98 99int xfrm_addr_match(xfrm_address_t *x1, xfrm_address_t *x2, int bits); 100int xfrm_xfrmproto_getbyname(char *name); 101int xfrm_algotype_getbyname(char *name); 102const char *strxf_xfrmproto(__u8 proto); 103const char *strxf_algotype(int type); 104const char *strxf_mask8(__u8 mask); 105const char *strxf_mask32(__u32 mask); 106const char *strxf_share(__u8 share); 107const char *strxf_proto(__u8 proto); 108void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id, 109 __u8 mode, __u32 reqid, __u16 family, int force_spi, 110 FILE *fp, const char *prefix, const char *title); 111void xfrm_stats_print(struct xfrm_stats *s, FILE *fp, const char *prefix); 112void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg, 113 struct xfrm_lifetime_cur *cur, 114 FILE *fp, const char *prefix); 115void xfrm_selector_print(struct xfrm_selector *sel, __u16 family, 116 FILE *fp, const char *prefix); 117void xfrm_xfrma_print(struct rtattr *tb[], __u16 family, 118 FILE *fp, const char *prefix); 119void xfrm_state_info_print(struct xfrm_usersa_info *xsinfo, 120 struct rtattr *tb[], FILE *fp, const char *prefix, 121 const char *title); 122void xfrm_policy_info_print(struct xfrm_userpolicy_info *xpinfo, 123 struct rtattr *tb[], FILE *fp, const char *prefix, 124 const char *title); 125int xfrm_id_parse(xfrm_address_t *saddr, struct xfrm_id *id, __u16 *family, 126 int loose, int *argcp, char ***argvp); 127int xfrm_mode_parse(__u8 *mode, int *argcp, char ***argvp); 128int xfrm_encap_type_parse(__u16 *type, int *argcp, char ***argvp); 129int xfrm_reqid_parse(__u32 *reqid, int *argcp, char ***argvp); 130int xfrm_selector_parse(struct xfrm_selector *sel, int *argcp, char ***argvp); 131int xfrm_lifetime_cfg_parse(struct xfrm_lifetime_cfg *lft, 132 int *argcp, char ***argvp); 133 134#endif 135