Lines Matching +full:sec +full:- +full:v4

1 // SPDX-License-Identifier: GPL-2.0
24 } rxcnt SEC(".maps");
31 } vip2tnl SEC(".maps");
52 return -1; in get_dport()
53 return th->dest; in get_dport()
57 return -1; in get_dport()
58 return uh->dest; in get_dport()
69 memcpy(new_eth->h_source, old_eth->h_dest, sizeof(new_eth->h_source)); in set_ethhdr()
70 memcpy(new_eth->h_dest, tnl->dmac, sizeof(new_eth->h_dest)); in set_ethhdr()
71 new_eth->h_proto = h_proto; in set_ethhdr()
76 void *data_end = (void *)(long)xdp->data_end; in handle_ipv4()
77 void *data = (void *)(long)xdp->data; in handle_ipv4()
92 dport = get_dport(iph + 1, data_end, iph->protocol); in handle_ipv4()
93 if (dport == -1) in handle_ipv4()
96 vip.protocol = iph->protocol; in handle_ipv4()
98 vip.daddr.v4 = iph->daddr; in handle_ipv4()
100 payload_len = bpf_ntohs(iph->tot_len); in handle_ipv4()
103 /* It only does v4-in-v4 */ in handle_ipv4()
104 if (!tnl || tnl->family != AF_INET) in handle_ipv4()
107 if (bpf_xdp_adjust_head(xdp, 0 - (int)sizeof(struct iphdr))) in handle_ipv4()
110 data = (void *)(long)xdp->data; in handle_ipv4()
111 data_end = (void *)(long)xdp->data_end; in handle_ipv4()
124 iph->version = 4; in handle_ipv4()
125 iph->ihl = sizeof(*iph) >> 2; in handle_ipv4()
126 iph->frag_off = 0; in handle_ipv4()
127 iph->protocol = IPPROTO_IPIP; in handle_ipv4()
128 iph->check = 0; in handle_ipv4()
129 iph->tos = 0; in handle_ipv4()
130 iph->tot_len = bpf_htons(payload_len + sizeof(*iph)); in handle_ipv4()
131 iph->daddr = tnl->daddr.v4; in handle_ipv4()
132 iph->saddr = tnl->saddr.v4; in handle_ipv4()
133 iph->ttl = 8; in handle_ipv4()
140 iph->check = ~((csum & 0xffff) + (csum >> 16)); in handle_ipv4()
149 void *data_end = (void *)(long)xdp->data_end; in handle_ipv6()
150 void *data = (void *)(long)xdp->data; in handle_ipv6()
162 dport = get_dport(ip6h + 1, data_end, ip6h->nexthdr); in handle_ipv6()
163 if (dport == -1) in handle_ipv6()
166 vip.protocol = ip6h->nexthdr; in handle_ipv6()
168 memcpy(vip.daddr.v6, ip6h->daddr.s6_addr32, sizeof(vip.daddr)); in handle_ipv6()
170 payload_len = ip6h->payload_len; in handle_ipv6()
173 /* It only does v6-in-v6 */ in handle_ipv6()
174 if (!tnl || tnl->family != AF_INET6) in handle_ipv6()
177 if (bpf_xdp_adjust_head(xdp, 0 - (int)sizeof(struct ipv6hdr))) in handle_ipv6()
180 data = (void *)(long)xdp->data; in handle_ipv6()
181 data_end = (void *)(long)xdp->data_end; in handle_ipv6()
193 ip6h->version = 6; in handle_ipv6()
194 ip6h->priority = 0; in handle_ipv6()
195 memset(ip6h->flow_lbl, 0, sizeof(ip6h->flow_lbl)); in handle_ipv6()
196 ip6h->payload_len = bpf_htons(bpf_ntohs(payload_len) + sizeof(*ip6h)); in handle_ipv6()
197 ip6h->nexthdr = IPPROTO_IPV6; in handle_ipv6()
198 ip6h->hop_limit = 8; in handle_ipv6()
199 memcpy(ip6h->saddr.s6_addr32, tnl->saddr.v6, sizeof(tnl->saddr.v6)); in handle_ipv6()
200 memcpy(ip6h->daddr.s6_addr32, tnl->daddr.v6, sizeof(tnl->daddr.v6)); in handle_ipv6()
207 SEC("xdp")
210 void *data_end = (void *)(long)xdp->data_end; in _xdp_tx_iptunnel()
211 void *data = (void *)(long)xdp->data; in _xdp_tx_iptunnel()
218 h_proto = eth->h_proto; in _xdp_tx_iptunnel()
229 char _license[] SEC("license") = "GPL";