我想通过添加Hop by Hop扩展头作为数据包下一个头来修改ipv6头。目前,使用libnetfilter_queue,我拦截Ipv6数据包并获取其Ipv6标头(printf src ip,dst ip,数据包长度和下一个标头类型)。
现在,我尝试没有成功完成这项任务:
if(ipv6 header已包含HopbyHop标头){存储此hopbyhop,在}之后使用它{else将此标头添加到存储的hopbyhop标头}。
有人能帮帮我吗?提前谢谢。int mycallBack( struct nfq_q_handle *hq, struct nfgenmsg *nfmsg, struct nfq_data *nfad, void *data){
unsigned int len, id, temp_id;
unsigned char *packet, payload[2048], buf[2048];
struct ip6_hdr *packet_header; //ipv6 header
char ip_addr_source[INET6_ADDRSTRLEN], ip_addr_destination[INET6_ADDRSTRLEN];
struct nfqnl_msg_packet_hdr *hp = nfq_get_msg_packet_hdr(nfad); //get packet header
if (hp != NULL) {
id = ntohl(hp->packet_id); // Get packet id
printf("Received packet n°: %d\n", id ); //printf received message
}
len = nfq_get_payload(nfad, &packet); //get payload length
packet_header = (struct ip6_hdr *) packet; // get ip header
inet_ntop(AF_INET6, &packet_header->ip6_src, ip_addr_source, INET6_ADDRSTRLEN); //get src ip
inet_ntop(AF_INET6, &packet_header->ip6_dst, ip_addr_destination, INET6_ADDRSTRLEN); //get dst ip
printf("Ip source: %s\n", ip_addr_source); //printf @
printf("Ip destination: %s\n", ip_addr_destination); //printf @
////////////////start Ip hearder modification /////////////////////
if(packet_header->ip6_nxt !=IPPROTO_HOPOPTS){ // IPPROTO_HOPOPTS=0
printf("Next header is not a HOP by Hop header \n\n");
//set a set ip6_nxt as a hopbyhop header and this hopbyhop ->next header as the firstly ip6_nxt ???
//and set a stored hopbyhop options data to the header ??
//struct ip6_hbh * hophdr= (struct ip6_hbh *)packet;
}else{
printf("Next header is already hopbyhop header);
//store the hopbyhop and its options data??
}
nfq_set_verdict(hq, id, NF_ACCEPT, 0, NULL); //resending of packet
return 0;
}