iptunnel_xmit函数是发送vxlan报文时,封装UDP报文头之后被调用的,主要作用是封装IP头,并调用三层发包函数,完成报文的发送,该函数相对比较简单。
1、iptunnel_xmit函数
int iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
__be32 src, __be32 dst, __u8 proto,
__u8 tos, __u8 ttl, __be16 df, bool xnet)
{
int pkt_len = skb->len;
struct iphdr *iph;
int err;
skb_scrub_packet(skb, xnet); //清空skb相关信息
skb_clear_hash(skb); //清空skb hash值
skb_dst_set(skb, &rt->dst); //rt必须根据外层报文的IP地址及相关信息获取到的
memset(IPCB(skb), 0, sizeof(*IPCB(skb))); //清空skb IPCB的内容
/* Push down and install the IP header. */
skb_push(skb, sizeof(struct iphdr)); //skb报文添加IP头
skb_reset_network_header(skb); //设置IP头的偏移
iph = ip_hdr(skb);
iph->version = 4;
iph->ihl = sizeof(struct iphdr) >> 2;
iph->frag_off = df; //OVS2.5默认有df标记
iph->protocol = proto; //vxlan,该协议为UDP
iph->tos = tos;
i