#ifndef _IP_FW_NAT64_TRANSLATE_H_
#define _IP_FW_NAT64_TRANSLATE_H_
struct nat64_stats {
uint64_t opcnt64;
uint64_t opcnt46;
uint64_t ofrags;
uint64_t ifrags;
uint64_t oerrors;
uint64_t noroute4;
uint64_t noroute6;
uint64_t nomatch4;
uint64_t noproto;
uint64_t nomem;
uint64_t dropped;
uint64_t jrequests;
uint64_t jcalls;
uint64_t jhostsreq;
uint64_t jportreq;
uint64_t jhostfails;
uint64_t jportfails;
uint64_t jmaxlen;
uint64_t jnomem;
uint64_t jreinjected;
uint64_t screated;
uint64_t sdeleted;
uint64_t spgcreated;
uint64_t spgdeleted;
};
#define IPFW_NAT64_VERSION 1
#define NAT64STATS (sizeof(struct nat64_stats) / sizeof(uint64_t))
struct nat64_counters {
counter_u64_t cnt[NAT64STATS];
};
#define NAT64STAT_ADD(s, f, v) \
counter_u64_add((s)->cnt[ \
offsetof(struct nat64_stats, f) / sizeof(uint64_t)], (v))
#define NAT64STAT_INC(s, f) NAT64STAT_ADD(s, f, 1)
#define NAT64STAT_FETCH(s, f) \
counter_u64_fetch((s)->cnt[ \
offsetof(struct nat64_stats, f) / sizeof(uint64_t)])
#define L3HDR(_ip, _t) ((_t)((uint32_t *)(_ip) + (_ip)->ip_hl))
#define TCP(p) ((struct tcphdr *)(p))
#define UDP(p) ((struct udphdr *)(p))
#define ICMP(p) ((struct icmphdr *)(p))
#define ICMP6(p) ((struct icmp6_hdr *)(p))
#define NAT64SKIP 0
#define NAT64RETURN 1
#define NAT64MFREE -1
struct nat64_config {
struct in6_addr clat_prefix;
struct in6_addr plat_prefix;
uint32_t flags;
#define NAT64_WKPFX 0x00010000
#define NAT64_CLATPFX 0x00020000
#define NAT64_PLATPFX 0x00040000
uint8_t clat_plen;
uint8_t plat_plen;
struct nat64_counters stats;
};
static inline int
nat64_check_ip6(struct in6_addr *addr)
{
if (addr->s6_addr16[0] == 0 ||
IN6_IS_ADDR_MULTICAST(addr) || IN6_IS_ADDR_LINKLOCAL(addr))
return (1);
return (0);
}
static inline int
nat64_check_ip4(in_addr_t ia)
{
if (IN_MULTICAST(ntohl(ia)) || IN_LOOPBACK(ntohl(ia)) ||
IN_LINKLOCAL(ntohl(ia)) || IN_EXPERIMENTAL(ntohl(ia)))
return (1);
return (0);
}
#define IPV6_ADDR_INT32_WKPFX htonl(0x64ff9b)
#define IN6_IS_ADDR_WKPFX(a) \
((a)->s6_addr32[0] == IPV6_ADDR_INT32_WKPFX && \
(a)->s6_addr32[1] == 0 && (a)->s6_addr32[2] == 0)
int nat64_check_private_ip4(const struct nat64_config *cfg, in_addr_t ia);
int nat64_check_prefixlen(int length);
int nat64_check_prefix6(const struct in6_addr *prefix, int length);
int nat64_getlasthdr(struct mbuf *m, int *offset);
int nat64_do_handle_ip4(struct mbuf *m, struct in6_addr *saddr,
struct in6_addr *daddr, uint16_t lport, struct nat64_config *cfg,
void *logdata);
int nat64_do_handle_ip6(struct mbuf *m, uint32_t aaddr, uint16_t aport,
struct nat64_config *cfg, void *logdata);
int nat64_handle_icmp6(struct mbuf *m, int hlen, uint32_t aaddr,
uint16_t aport, struct nat64_config *cfg, void *logdata);
void nat64_embed_ip4(struct in6_addr *ip6, int plen, in_addr_t ia);
in_addr_t nat64_extract_ip4(const struct in6_addr *ip6, int plen);
void nat64_set_output_method(int);
int nat64_get_output_method(void);
#endif