完成polling接口改造和重复流量识别功能
This commit is contained in:
@@ -3,22 +3,24 @@
|
||||
#include <netinet/ip6.h>
|
||||
#include <net/if.h>
|
||||
|
||||
int kni_stream_addr_trans(const struct layer_addr *addr, addr_type_t addr_type, char *output, int len){
|
||||
int kni_addr_trans_v4(struct stream_tuple4_v4 *tuple4, char *output, int len){
|
||||
char saddr[INET_ADDRSTRLEN];
|
||||
char daddr[INET_ADDRSTRLEN];
|
||||
inet_ntop(AF_INET, &(tuple4->saddr), saddr, INET_ADDRSTRLEN);
|
||||
inet_ntop(AF_INET, &(tuple4->daddr), daddr, INET_ADDRSTRLEN);
|
||||
uint16_t source = ntohs(tuple4->source);
|
||||
uint16_t dest = ntohs(tuple4->dest);
|
||||
snprintf(output, len, "%s:%d -> %s:%d", saddr, source, daddr, dest);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int kni_addr_trans_v6(struct stream_tuple4_v6 *tuple4, char *output, int len){
|
||||
char saddr[INET6_ADDRSTRLEN];
|
||||
char daddr[INET6_ADDRSTRLEN];
|
||||
uint16_t source, dest;
|
||||
if(addr_type == ADDR_TYPE_IPV6){
|
||||
inet_ntop(AF_INET6, &(addr->tuple4_v6->saddr), saddr, INET6_ADDRSTRLEN);
|
||||
inet_ntop(AF_INET6, &(addr->tuple4_v6->daddr), daddr, INET6_ADDRSTRLEN);
|
||||
source = ntohs(addr->tuple4_v6->source);
|
||||
dest = ntohs(addr->tuple4_v6->dest);
|
||||
}
|
||||
else{
|
||||
inet_ntop(AF_INET, &(addr->tuple4_v4->saddr), saddr, INET6_ADDRSTRLEN);
|
||||
inet_ntop(AF_INET, &(addr->tuple4_v4->daddr), daddr, INET6_ADDRSTRLEN);
|
||||
source = ntohs(addr->tuple4_v4->source);
|
||||
dest = ntohs(addr->tuple4_v4->dest);
|
||||
}
|
||||
inet_ntop(AF_INET6, tuple4->saddr, saddr, INET6_ADDRSTRLEN);
|
||||
inet_ntop(AF_INET6, tuple4->daddr, daddr, INET6_ADDRSTRLEN);
|
||||
uint16_t source = ntohs(tuple4->source);
|
||||
uint16_t dest = ntohs(tuple4->dest);
|
||||
snprintf(output, len, "%s:%d -> %s:%d", saddr, source, daddr, dest);
|
||||
return 0;
|
||||
}
|
||||
@@ -195,7 +197,8 @@ struct kni_tcpopt_info* kni_get_tcpopt(struct tcphdr* tcphdr,int tcphdr_len){
|
||||
break;
|
||||
case TCPOPT_TIMESTAMP:
|
||||
if ((opsize == TCPOLEN_TIMESTAMP)){
|
||||
tcpopt->ts = 1;
|
||||
tcpopt->ts_set = 1;
|
||||
tcpopt->ts_value = *(uint32_t*)ptr;
|
||||
}
|
||||
break;
|
||||
case TCPOPT_SACK_PERMITTED:
|
||||
@@ -333,6 +336,7 @@ int kni_ipv4_header_parse(const void *a_packet, struct pkt_info *pktinfo){
|
||||
if(a_packet == NULL){
|
||||
return KNI_IPV4HDR_PARSE_ERROR_NULL_PACKET;
|
||||
}
|
||||
pktinfo->addr_type = ADDR_TYPE_IPV4;
|
||||
pktinfo->iphdr.v4 = (struct iphdr*)a_packet;
|
||||
pktinfo->iphdr_len = pktinfo->iphdr.v4->ihl * 4;
|
||||
pktinfo->ip_totlen = ntohs(pktinfo->iphdr.v4->tot_len);
|
||||
@@ -347,6 +351,7 @@ int kni_ipv6_header_parse(const void *a_packet, struct pkt_info *pktinfo){
|
||||
if(a_packet == NULL){
|
||||
return KNI_IPV6HDR_PARSE_ERROR_NULL_PACKET;
|
||||
}
|
||||
pktinfo->addr_type = ADDR_TYPE_IPV6;
|
||||
pktinfo->iphdr.v6 = (struct ip6_hdr*)a_packet;
|
||||
pktinfo->ip_totlen = ntohs(pktinfo->iphdr.v6->ip6_ctlun.ip6_un1.ip6_un1_plen) + sizeof(struct ip6_hdr);
|
||||
uint8_t next_hdr_type = pktinfo->iphdr.v6->ip6_ctlun.ip6_un1.ip6_un1_nxt;
|
||||
|
||||
Reference in New Issue
Block a user