rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | #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*/ |
| 15 | extern int setkey_flushSAD(void); |
| 16 | extern int setkey_flushSAD_xfrm(char * ipsec_type); |
| 17 | /*flush all SP*/ |
| 18 | extern int setkey_flushSPD(void); |
| 19 | extern int setkey_flushSPD_xfrm(void); |
| 20 | /*delete one SA entry*/ |
| 21 | extern int setkey_deleteSA(char * src,char * dst,char * ipsec_type,char * spi_src); |
| 22 | extern int setkey_deleteSA_xfrm(char * src,char * dst,char * ipsec_type,char * spi_src); |
| 23 | |
| 24 | /*delete one SP entry*/ |
| 25 | int setkey_deleteSP(char * src,char * dst,enum PROTOCOL_TYPE protocol,char * src_port,char * dst_port,char * direction); |
| 26 | int setkey_deleteSP_xfrm(char * src,char * dst,enum PROTOCOL_TYPE protocol,char * src_port,char * dst_port,char * direction); |
| 27 | |
| 28 | /*dump all SA */ |
| 29 | extern int dump_setkeySA(void); |
| 30 | |
| 31 | /*dump all SP */ |
| 32 | extern 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 | */ |
| 42 | extern 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); |
| 43 | extern 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 | |
| 45 | extern 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 */ |
| 51 | extern 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); |
| 52 | extern 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 |
| 57 | src_tunnel,dst_tunnel: tunnel src ip tunnel dst ip */ |
| 58 | extern 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 |
| 64 | src_tunnel,dst_tunnel: tunnel src ip tunnel dst ip */ |
| 65 | extern 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*/ |
| 70 | int 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 |
| 76 | src_tunnel,dst_tunnel: tunnel src ip tunnel dst ip */ |
| 77 | int 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); |
| 78 | int 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*/ |
| 81 | extern int flush_SA_SP_exist(); |
| 82 | extern int flush_SA_SP_exist_xfrm(); |
| 83 | |