增加ipv6支持

This commit is contained in:
崔一鸣
2019-06-14 11:13:15 +08:00
parent 3ed1bac877
commit 02abbae3d9
5 changed files with 546 additions and 225 deletions

View File

@@ -6,7 +6,6 @@
#include <pthread.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <time.h>
#include "MESA/MESA_handle_logger.h"
#include "MESA/MESA_htable.h"
@@ -92,6 +91,10 @@ enum kni_field{
KNI_FIELD_ID2PME_ADD_FAIL,
KNI_FIELD_ID2PME_DEL_SUCC,
KNI_FIELD_ID2PME_DEL_FAIL,
KNI_FIELD_IPV4HDR_PARSE_FAIL,
KNI_FIELD_IPV6HDR_PARSE_FAIL,
KNI_FIELD_KEEPALIVE_REPLAY_ADD_SUCC,
KNI_FIELD_KEEPALIVE_REPLAY_ADD_FAIL,
};
struct kni_field_stat_handle{
@@ -99,12 +102,40 @@ struct kni_field_stat_handle{
int fields[KNI_FIELD_MAX];
};
int kni_stream_addr_trans(const struct layer_addr *addr, char *output, int len);
struct pkt_info{
union{
struct iphdr *v4;
struct ip6_hdr *v6;
}iphdr;
uint16_t iphdr_len;
uint16_t ip_totlen;
struct tcphdr *tcphdr;
uint16_t tcphdr_len;
char *data;
uint16_t data_len;
};
enum kni_ipv4hdr_parse_error{
KNI_IPV4HDR_PARSE_ERROR_NULL_PACKET = -1,
};
enum kni_ipv6hdr_parse_error{
KNI_IPV6HDR_PARSE_ERROR_NULL_PACKET = -1,
KNI_IPV6HDR_PARSE_ERROR_NO_TCPHDR = -2,
KNI_IPV6HDR_PARSE_ERROR_INVALID_TYPE = -3,
};
int kni_stream_addr_trans(const struct layer_addr *addr, addr_type_t addr_type, char *output, int len);
uint16_t kni_ip_checksum(const void *buf, size_t hdr_len);
uint16_t kni_tcp_checksum(const void *_buf, size_t len, in_addr_t src_addr, in_addr_t dest_addr);
uint16_t kni_tcp_checksum_v6(const void *_buf, size_t len, struct in6_addr src_addr, struct in6_addr dest_addr);
uint16_t kni_udp_checksum(const void *_buf, size_t len, in_addr_t src_addr, in_addr_t dest_addr);
struct kni_tcpopt_info* kni_get_tcpopt(struct tcphdr* tcphdr,int tcphdr_len);
struct kni_tcpopt_info* kni_get_tcpopt(struct tcphdr* tcphdr, int tcphdr_len);
int kni_ipv4_addr_get_by_eth(const char *ifname, uint32_t *ip);
int kni_ipv4_header_parse(const void *a_packet, struct pkt_info *pktinfo);
int kni_ipv6_header_parse(const void *a_packet, struct pkt_info *pktinfo);
char* kni_ipv4_errmsg_get(enum kni_ipv4hdr_parse_error _errno);
char* kni_ipv6_errmsg_get(enum kni_ipv6hdr_parse_error _errno);
MESA_htable_handle kni_create_htable(const char *profile, const char *section, void *free_data_cb, void *expire_notify_cb, void *logger);