}
}
+static void print_range_xlate(const struct nf_nat_ipv4_range *r,
+ struct xt_buf *buf)
+{
+ if (r->flags & NF_NAT_RANGE_MAP_IPS) {
+ struct in_addr a;
+
+ a.s_addr = r->min_ip;
+ xt_buf_add(buf, "%s", xtables_ipaddr_to_numeric(&a));
+ if (r->max_ip != r->min_ip) {
+ a.s_addr = r->max_ip;
+ xt_buf_add(buf, "-%s", xtables_ipaddr_to_numeric(&a));
+ }
+ }
+ if (r->flags & NF_NAT_RANGE_PROTO_SPECIFIED) {
+ xt_buf_add(buf, ":%hu", ntohs(r->min.tcp.port));
+ if (r->max.tcp.port != r->min.tcp.port)
+ xt_buf_add(buf, "-%hu", ntohs(r->max.tcp.port));
+ }
+}
+
+static int DNAT_xlate(const struct xt_entry_target *target,
+ struct xt_buf *buf, int numeric)
+{
+ const struct ipt_natinfo *info = (const void *)target;
+ unsigned int i = 0;
+ bool sep_need = false;
+ const char *sep = " ";
+
+ for (i = 0; i < info->mr.rangesize; i++) {
+ xt_buf_add(buf, "dnat ");
+ print_range_xlate(&info->mr.range[i], buf);
+ if (info->mr.range[i].flags & NF_NAT_RANGE_PROTO_RANDOM) {
+ xt_buf_add(buf, " random");
+ sep_need = true;
+ }
+ if (info->mr.range[i].flags & NF_NAT_RANGE_PERSISTENT) {
+ if (sep_need)
+ sep = ",";
+ xt_buf_add(buf, "%spersistent", sep);
+ }
+ }
+
+ return 1;
+}
+
static struct xtables_target dnat_tg_reg = {
.name = "DNAT",
.version = XTABLES_VERSION,
.print = DNAT_print,
.save = DNAT_save,
.x6_options = DNAT_opts,
+ .xlate = DNAT_xlate,
};
void _init(void)