TSG-17749 tsg-service-chaining-engine更改VXLAN Frame源端口的计算方式
This commit is contained in:
@@ -153,79 +153,6 @@ void throughput_metrics_inc(struct throughput_metrics *iterm, uint64_t n_pkts, u
|
||||
iterm->n_pkts += n_pkts;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* protocol
|
||||
******************************************************************************/
|
||||
int checksum(uint16_t *addr, int len)
|
||||
{
|
||||
int sum = 0;
|
||||
int nleft = len;
|
||||
uint16_t ans = 0;
|
||||
uint16_t *w = addr;
|
||||
|
||||
while (nleft > 1)
|
||||
{
|
||||
sum += *w++;
|
||||
nleft -= 2;
|
||||
}
|
||||
|
||||
if (nleft == 1)
|
||||
{
|
||||
*(char *)(&ans) = *(char *)w;
|
||||
sum += ans;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
void build_udp_header(const char *l3_hdr, int l3_hdr_len, struct udp_hdr *udp_hdr, uint16_t udp_sport, uint16_t udp_dport, int payload_len)
|
||||
{
|
||||
memset(udp_hdr, 0, sizeof(struct udp_hdr));
|
||||
|
||||
int udp_hlen = sizeof(struct udp_hdr) + payload_len;
|
||||
|
||||
udp_hdr->uh_sport = htons(udp_sport);
|
||||
udp_hdr->uh_dport = htons(udp_dport);
|
||||
|
||||
udp_hdr->uh_ulen = htons(udp_hlen);
|
||||
udp_hdr->uh_sum = 0;
|
||||
|
||||
int sum = checksum((uint16_t *)l3_hdr, l3_hdr_len);
|
||||
sum += ntohs(IPPROTO_UDP + udp_hlen);
|
||||
sum += checksum((uint16_t *)udp_hdr, udp_hlen);
|
||||
udp_hdr->uh_sum = CHECKSUM_CARRY(sum);
|
||||
}
|
||||
|
||||
void build_ip_header(struct ip *ip_hdr, uint8_t next_protocol, uint16_t ipid, const in_addr_t src_ip, const in_addr_t dst_ip, uint16_t payload_len)
|
||||
{
|
||||
memset(ip_hdr, 0, sizeof(struct ip));
|
||||
|
||||
ip_hdr->ip_hl = 5; /* 20 byte header */
|
||||
ip_hdr->ip_v = 4; /* version 4 */
|
||||
ip_hdr->ip_tos = 0; /* IP tos */
|
||||
ip_hdr->ip_id = htons(ipid); /* IP ID */
|
||||
ip_hdr->ip_ttl = 80; /* time to live */
|
||||
ip_hdr->ip_p = next_protocol; /* transport protocol */
|
||||
ip_hdr->ip_src.s_addr = src_ip;
|
||||
ip_hdr->ip_dst.s_addr = dst_ip;
|
||||
ip_hdr->ip_len = htons(sizeof(struct ip) + payload_len); /* total length */
|
||||
ip_hdr->ip_off = htons(0); /* fragmentation flags */
|
||||
ip_hdr->ip_sum = 0; /* do this later */
|
||||
|
||||
int sum = checksum((uint16_t *)ip_hdr, 20);
|
||||
ip_hdr->ip_sum = CHECKSUM_CARRY(sum);
|
||||
}
|
||||
|
||||
// l3_protocol: ETH_P_IPV6/ETH_P_IP
|
||||
void build_ether_header(struct ethhdr *eth_hdr, uint16_t next_protocol, const u_char src_mac[], const u_char dst_mac[])
|
||||
{
|
||||
memset(eth_hdr, 0, sizeof(struct ethhdr));
|
||||
|
||||
memcpy(eth_hdr->h_source, src_mac, ETH_ALEN);
|
||||
memcpy(eth_hdr->h_dest, dst_mac, ETH_ALEN);
|
||||
eth_hdr->h_proto = htons(next_protocol);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* device
|
||||
******************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user