diff options
Diffstat (limited to 'translate.h')
-rw-r--r-- | translate.h | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/translate.h b/translate.h index fded251..5efa817 100644 --- a/translate.h +++ b/translate.h @@ -18,17 +18,29 @@ #ifndef __TRANSLATE_H__ #define __TRANSLATE_H__ +#include <netinet/in.h> +#include <netinet/ip.h> +#include <netinet/ip_icmp.h> +#include <netinet/udp.h> +#include <netinet/tcp.h> +#include <netinet/ip6.h> +#include <netinet/icmp6.h> +#include <linux/icmp.h> #include <linux/if_tun.h> +#include "clatd.h" + #define MAX_TCP_HDR (15 * 4) // Data offset field is 4 bits and counts in 32-bit words. // A clat_packet is an array of iovec structures representing a packet that we are translating. // The CLAT_POS_XXX constants represent the array indices within the clat_packet that contain // specific parts of the packet. The packet_* functions operate on all the packet segments past a // given position. -enum clat_packet_index { CLAT_POS_TUNHDR, CLAT_POS_IPHDR, CLAT_POS_TRANSPORTHDR, - CLAT_POS_ICMPERR_IPHDR, CLAT_POS_ICMPERR_TRANSPORTHDR, - CLAT_POS_PAYLOAD, CLAT_POS_MAX }; +enum clat_packet_index { + CLAT_POS_TUNHDR, CLAT_POS_IPHDR, CLAT_POS_FRAGHDR, CLAT_POS_TRANSPORTHDR, + CLAT_POS_ICMPERR_IPHDR, CLAT_POS_ICMPERR_FRAGHDR, CLAT_POS_ICMPERR_TRANSPORTHDR, + CLAT_POS_PAYLOAD, CLAT_POS_MAX +}; typedef struct iovec clat_packet[CLAT_POS_MAX]; // Calculates the checksum over all the packet components starting from pos. @@ -47,19 +59,37 @@ void fill_ip_header(struct iphdr *ip_targ, uint16_t payload_len, uint8_t protoco void fill_ip6_header(struct ip6_hdr *ip6, uint16_t payload_len, uint8_t protocol, const struct iphdr *old_header); +// Translate and send packets. +void translate_packet(const struct tun_data *tunnel, struct tun_pi *tun_header, const char *packet, + size_t packetsize); + +// Translate IPv4 and IPv6 packets. +int ipv4_packet(clat_packet out, int pos, const char *packet, size_t len); +int ipv6_packet(clat_packet out, int pos, const char *packet, size_t len); + +// Deal with fragmented packets. +size_t maybe_fill_frag_header(struct ip6_frag *frag_hdr, struct ip6_hdr *ip6_targ, + const struct iphdr *old_header); +uint8_t parse_frag_header(const struct ip6_frag *frag_hdr, struct iphdr *ip_targ); + // Translate ICMP packets. int icmp_to_icmp6(clat_packet out, int pos, const struct icmphdr *icmp, uint32_t checksum, const char *payload, size_t payload_size); -int icmp6_to_icmp(clat_packet out, int pos, const struct icmp6_hdr *icmp6, uint32_t checksum, +int icmp6_to_icmp(clat_packet out, int pos, const struct icmp6_hdr *icmp6, const char *payload, size_t payload_size); +// Translate generic IP packets. +int generic_packet(clat_packet out, int pos, const char *payload, size_t len); + // Translate TCP and UDP packets. -int tcp_packet(clat_packet out, int pos, const struct tcphdr *tcp, uint32_t checksum, size_t len); -int udp_packet(clat_packet out, int pos, const struct udphdr *udp, uint32_t checksum, size_t len); +int tcp_packet(clat_packet out, int pos, const struct tcphdr *tcp, + uint32_t old_sum, uint32_t new_sum, size_t len); +int udp_packet(clat_packet out, int pos, const struct udphdr *udp, + uint32_t old_sum, uint32_t new_sum, size_t len); int tcp_translate(clat_packet out, int pos, const struct tcphdr *tcp, size_t header_size, - uint32_t checksum, const char *payload, size_t payload_size); -int udp_translate(clat_packet out, int pos, const struct udphdr *udp, uint32_t checksum, - const char *payload, size_t payload_size); + uint32_t old_sum, uint32_t new_sum, const char *payload, size_t payload_size); +int udp_translate(clat_packet out, int pos, const struct udphdr *udp, + uint32_t old_sum, uint32_t new_sum, const char *payload, size_t payload_size); #endif /* __TRANSLATE_H__ */ |