Lines Matching +full:sec +full:- +full:v4
1 // SPDX-License-Identifier: GPL-2.0
25 } rxcnt SEC(".maps");
32 } vip2tnl SEC(".maps");
53 return -1; in get_dport()
54 return th->dest; in get_dport()
58 return -1; in get_dport()
59 return uh->dest; in get_dport()
70 memcpy(new_eth->h_source, old_eth->h_dest, sizeof(new_eth->h_source)); in set_ethhdr()
71 memcpy(new_eth->h_dest, tnl->dmac, sizeof(new_eth->h_dest)); in set_ethhdr()
72 new_eth->h_proto = h_proto; in set_ethhdr()
77 void *data_end = (void *)(long)xdp->data_end; in handle_ipv4()
78 void *data = (void *)(long)xdp->data; in handle_ipv4()
93 dport = get_dport(iph + 1, data_end, iph->protocol); in handle_ipv4()
94 if (dport == -1) in handle_ipv4()
97 vip.protocol = iph->protocol; in handle_ipv4()
99 vip.daddr.v4 = iph->daddr; in handle_ipv4()
101 payload_len = bpf_ntohs(iph->tot_len); in handle_ipv4()
104 /* It only does v4-in-v4 */ in handle_ipv4()
105 if (!tnl || tnl->family != AF_INET) in handle_ipv4()
108 if (bpf_xdp_adjust_head(xdp, 0 - (int)sizeof(struct iphdr))) in handle_ipv4()
111 data = (void *)(long)xdp->data; in handle_ipv4()
112 data_end = (void *)(long)xdp->data_end; in handle_ipv4()
125 iph->version = 4; in handle_ipv4()
126 iph->ihl = sizeof(*iph) >> 2; in handle_ipv4()
127 iph->frag_off = 0; in handle_ipv4()
128 iph->protocol = IPPROTO_IPIP; in handle_ipv4()
129 iph->check = 0; in handle_ipv4()
130 iph->tos = 0; in handle_ipv4()
131 iph->tot_len = bpf_htons(payload_len + sizeof(*iph)); in handle_ipv4()
132 iph->daddr = tnl->daddr.v4; in handle_ipv4()
133 iph->saddr = tnl->saddr.v4; in handle_ipv4()
134 iph->ttl = 8; in handle_ipv4()
141 iph->check = ~((csum & 0xffff) + (csum >> 16)); in handle_ipv4()
150 void *data_end = (void *)(long)xdp->data_end; in handle_ipv6()
151 void *data = (void *)(long)xdp->data; in handle_ipv6()
163 dport = get_dport(ip6h + 1, data_end, ip6h->nexthdr); in handle_ipv6()
164 if (dport == -1) in handle_ipv6()
167 vip.protocol = ip6h->nexthdr; in handle_ipv6()
169 memcpy(vip.daddr.v6, ip6h->daddr.s6_addr32, sizeof(vip.daddr)); in handle_ipv6()
171 payload_len = ip6h->payload_len; in handle_ipv6()
174 /* It only does v6-in-v6 */ in handle_ipv6()
175 if (!tnl || tnl->family != AF_INET6) in handle_ipv6()
178 if (bpf_xdp_adjust_head(xdp, 0 - (int)sizeof(struct ipv6hdr))) in handle_ipv6()
181 data = (void *)(long)xdp->data; in handle_ipv6()
182 data_end = (void *)(long)xdp->data_end; in handle_ipv6()
194 ip6h->version = 6; in handle_ipv6()
195 ip6h->priority = 0; in handle_ipv6()
196 memset(ip6h->flow_lbl, 0, sizeof(ip6h->flow_lbl)); in handle_ipv6()
197 ip6h->payload_len = bpf_htons(bpf_ntohs(payload_len) + sizeof(*ip6h)); in handle_ipv6()
198 ip6h->nexthdr = IPPROTO_IPV6; in handle_ipv6()
199 ip6h->hop_limit = 8; in handle_ipv6()
200 memcpy(ip6h->saddr.s6_addr32, tnl->saddr.v6, sizeof(tnl->saddr.v6)); in handle_ipv6()
201 memcpy(ip6h->daddr.s6_addr32, tnl->daddr.v6, sizeof(tnl->daddr.v6)); in handle_ipv6()
208 SEC("xdp")
211 void *data_end = (void *)(long)xdp->data_end; in _xdp_tx_iptunnel()
212 void *data = (void *)(long)xdp->data; in _xdp_tx_iptunnel()
219 h_proto = eth->h_proto; in _xdp_tx_iptunnel()
230 char _license[] SEC("license") = "GPL";