rename layer_type to layer_proto

This commit is contained in:
luwenpeng
2024-06-12 18:21:45 +08:00
parent 10528bcfd3
commit 01958b56c5
20 changed files with 437 additions and 1049 deletions

View File

@@ -254,7 +254,7 @@ static int build_tcp_packet(const struct packet *first, uint16_t ip_id, uint8_t
curr = (struct packet_layer *)packet_get_layer(first, i);
switch (curr->type)
{
case LAYER_TYPE_TCP:
case LAYER_PROTO_TCP:
trim = curr->hdr_len + curr->pld_len - sizeof(struct tcphdr) - pld_len;
if (len - trim > buff_size)
{
@@ -267,41 +267,41 @@ static int build_tcp_packet(const struct packet *first, uint16_t ip_id, uint8_t
memcpy(pkt_buff + curr->hdr_offset + sizeof(struct tcphdr), tcp_pld, pld_len);
}
break;
case LAYER_TYPE_UDP:
case LAYER_PROTO_UDP:
udphdr = (struct udphdr *)(pkt_buff + curr->hdr_offset);
update_udp_hdr(udphdr, trim);
break;
case LAYER_TYPE_IPV4:
case LAYER_PROTO_IPV4:
iphdr = (struct ip *)(pkt_buff + curr->hdr_offset);
last = (struct packet_layer *)packet_get_layer(first, i + 1);
if (last->type == LAYER_TYPE_TCP)
if (last->type == LAYER_PROTO_TCP)
{
tcphdr = (struct tcphdr *)(pkt_buff + last->hdr_offset);
tcphdr->th_sum = checksum_v4(tcphdr, len - trim - last->hdr_offset, IPPROTO_TCP, &iphdr->ip_src, &iphdr->ip_dst);
}
if (last->type == LAYER_TYPE_UDP)
if (last->type == LAYER_PROTO_UDP)
{
udphdr = (struct udphdr *)(pkt_buff + last->hdr_offset);
udphdr->uh_sum = checksum_v4(udphdr, len - trim - last->hdr_offset, IPPROTO_UDP, &iphdr->ip_src, &iphdr->ip_dst);
}
update_ip4_hdr(iphdr, ip_id, ip_ttl, trim);
break;
case LAYER_TYPE_IPV6:
case LAYER_PROTO_IPV6:
ip6hdr = (struct ip6_hdr *)(pkt_buff + curr->hdr_offset);
last = (struct packet_layer *)packet_get_layer(first, i + 1);
if (last->type == LAYER_TYPE_TCP)
if (last->type == LAYER_PROTO_TCP)
{
tcphdr = (struct tcphdr *)(pkt_buff + last->hdr_offset);
tcphdr->th_sum = checksum_v6(tcphdr, len - trim - last->hdr_offset, IPPROTO_TCP, &ip6hdr->ip6_src, &ip6hdr->ip6_dst);
}
if (last->type == LAYER_TYPE_UDP)
if (last->type == LAYER_PROTO_UDP)
{
udphdr = (struct udphdr *)(pkt_buff + last->hdr_offset);
udphdr->uh_sum = checksum_v6(udphdr, len - trim - last->hdr_offset, IPPROTO_UDP, &ip6hdr->ip6_src, &ip6hdr->ip6_dst);
}
update_ip6_hdr(ip6hdr, trim);
break;
case LAYER_TYPE_GRE:
case LAYER_PROTO_GRE:
return -EPROTONOSUPPORT;
// TODO
break;
@@ -341,7 +341,7 @@ static int build_udp_packet(const struct packet *first, const char *udp_pld, int
curr = (struct packet_layer *)packet_get_layer(first, i);
switch (curr->type)
{
case LAYER_TYPE_UDP:
case LAYER_PROTO_UDP:
trim = curr->hdr_len + curr->pld_len - sizeof(struct udphdr) - pld_len;
if (len - trim > buff_size)
{
@@ -354,27 +354,27 @@ static int build_udp_packet(const struct packet *first, const char *udp_pld, int
memcpy(pkt_buff + curr->hdr_offset + sizeof(struct udphdr), udp_pld, pld_len);
}
break;
case LAYER_TYPE_IPV4:
case LAYER_PROTO_IPV4:
iphdr = (struct ip *)(pkt_buff + curr->hdr_offset);
last = (struct packet_layer *)packet_get_layer(first, i + 1);
if (last->type == LAYER_TYPE_UDP)
if (last->type == LAYER_PROTO_UDP)
{
udphdr = (struct udphdr *)(pkt_buff + last->hdr_offset);
udphdr->uh_sum = checksum_v4(udphdr, len - trim - last->hdr_offset, IPPROTO_UDP, &iphdr->ip_src, &iphdr->ip_dst);
}
update_ip4_hdr(iphdr, 0, 0, trim);
break;
case LAYER_TYPE_IPV6:
case LAYER_PROTO_IPV6:
ip6hdr = (struct ip6_hdr *)(pkt_buff + curr->hdr_offset);
last = (struct packet_layer *)packet_get_layer(first, i + 1);
if (last->type == LAYER_TYPE_UDP)
if (last->type == LAYER_PROTO_UDP)
{
udphdr = (struct udphdr *)(pkt_buff + last->hdr_offset);
udphdr->uh_sum = checksum_v6(udphdr, len - trim - last->hdr_offset, IPPROTO_UDP, &ip6hdr->ip6_src, &ip6hdr->ip6_dst);
}
update_ip6_hdr(ip6hdr, trim);
break;
case LAYER_TYPE_GRE:
case LAYER_PROTO_GRE:
return -EPROTONOSUPPORT;
// TODO
break;