blob: 141ecb37d468098d6498a276847e9f089f01b133 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <ctype.h>
5#include <unistd.h>
6#include <errno.h>
7#include <netdb.h>
8#include <fcntl.h>
9#include <dirent.h>
10#include <time.h>
11#include "utils_xfrm.h"
12
13
14/*flush all SA*/
15extern int setkey_flushSAD(void);
16extern int setkey_flushSAD_xfrm(char * ipsec_type);
17/*flush all SP*/
18extern int setkey_flushSPD(void);
19extern int setkey_flushSPD_xfrm(void);
20/*delete one SA entry*/
21extern int setkey_deleteSA(char * src,char * dst,char * ipsec_type,char * spi_src);
22extern int setkey_deleteSA_xfrm(char * src,char * dst,char * ipsec_type,char * spi_src);
23
24/*delete one SP entry*/
25int setkey_deleteSP(char * src,char * dst,enum PROTOCOL_TYPE protocol,char * src_port,char * dst_port,char * direction);
26int setkey_deleteSP_xfrm(char * src,char * dst,enum PROTOCOL_TYPE protocol,char * src_port,char * dst_port,char * direction);
27
28/*dump all SA */
29extern int dump_setkeySA(void);
30
31/*dump all SP */
32extern int dump_setkeySP(void);
33
34/*set one SA*/
35/*ipsec_type:ah esp
36 mode:transport tunnel
37 encrp_algo_src:encryption algorithm,des-cbc,3des-cbc...
38 encrp_algo_src:key of encryption algorithm
39 intergrity_algo_src:authentication algorithm ,hmac-md5,hmac-sha1
40 intergrity_key_src:key of authentication algorithm
41*/
42extern int setkey_setSA(char * ip_src,char * ip_dst,char * ipsec_type,char * spi_src,char * mode, char * encrp_algo_src,char * encrp_key_src,char * intergrity_algo_src,char * intergrity_key_src,int u_id);
43extern int setkey_setSA_xfrm(int cmd,char * ip_src,char * ip_dst,char * ipsec_type,char * spi_src,char * mode, char * encrp_algo_src,char * encrp_key_src,char * intergrity_algo_src,char * intergrity_key_src,int u_id);
44
45extern int setkey_setSA_update(char * ip_src,char * ip_dst,char * ipsec_type,char * spi_src,char * mode,
46 char * encrp_algo_src,char * encrp_key_src,char * intergrity_algo_src,char * intergrity_key_src,int u_id);
47
48/*set one SP of one direction just for transport mode*/
49/*protocol:tcp icmp udp icmp6 ip4 gre
50 direction:src->dst */
51extern int setkey_SP(char * src_range,char * dst_range,enum PROTOCOL_TYPE protocol,char * port_src,char * port_dst,char * ipsec_type,char * mode, char * direction,int u_id);
52extern int setkey_SP_xfrm(int cmd,char * src_range,char * dst_range,enum PROTOCOL_TYPE protocol,char * port_src,char * port_dst,char * src_tunnel,char * dst_tunnel,char * ipsec_type,char * mode, char * direction,int u_id);
53
54/*set one SP of one direction, just for tunnel mode*/
55/*protocol:tcp icmp udp icmp6 ip4 gre
56 direction:src->dst
57src_tunnel,dst_tunnel: tunnel src ip tunnel dst ip */
58extern int setkey_SP_tunnel(char * src_range,char * dst_range,enum PROTOCOL_TYPE protocol,char * port_src,char * port_dst,char * src_tunnel,char * dst_tunnel,char * ipsec_type,char * mode, char * direction,int u_id);
59
60
61/*set one SP of one direction, for 2 layers' ipsec--tunnel mode+transport mode or transport mode+tunnel mode*/
62/*protocol:tcp icmp udp icmp6 ip4 gre
63 direction:src->dst
64src_tunnel,dst_tunnel: tunnel src ip tunnel dst ip */
65extern int setkey_SP_tunnel_transport(char * src_range,char * dst_range,enum PROTOCOL_TYPE protocol,char * port_src,char * port_dst,char * src_tunnel,char * dst_tunnel,char * ipsec_type1,char * mode1, char * ipsec_type2,char * mode2,char * direction,int u_id1,int u_id2);
66
67/*update one SP of one direction, just for transport mode*/
68/*protocol:tcp icmp udp icmp6 ip4 gre
69 direction:src->dst*/
70int setkey_SP_update_transport(char * src_range,char * dst_range,enum PROTOCOL_TYPE protocol,char * port_src,char * port_dst,char * ipsec_type, char * direction,int u_id);
71
72
73/*update one SP of one direction, for 2 layers' ipsec--tunnel mode+transport mode or transport mode+tunnel mode*/
74/*protocol:tcp icmp udp icmp6 ip4 gre
75 direction:src->dst
76src_tunnel,dst_tunnel: tunnel src ip tunnel dst ip */
77int setkey_SP_update_tunnel_transport(char * src_range,char * dst_range,enum PROTOCOL_TYPE protocol,char * port_src,char * port_dst,char * src_tunnel,char * dst_tunnel,char * ipsec_type1,char * mode1, char * ipsec_type2,char * mode2,char * direction,int u_id1,int u_id2);
78int setkey_SP_2layer_xfrm(int cmd,char * src_range,char * dst_range,enum PROTOCOL_TYPE protocol,char * port_src,char * port_dst,char * src_tunnel,char * dst_tunnel,char * ipsec_type1,char * mode1, char * ipsec_type2,char * mode2,char * direction,int u_id1,int u_id2);
79
80/*flush SA\SP from setkey.conf*/
81extern int flush_SA_SP_exist();
82extern int flush_SA_SP_exist_xfrm();
83