}
static void print_range_xlate(const struct nf_nat_range *range,
- struct xt_buf *buf)
+ struct xt_xlate *xl)
{
if (range->flags & NF_NAT_RANGE_MAP_IPS) {
- xt_buf_add(buf, "%s",
+ xt_xlate_add(xl, "%s",
xtables_ip6addr_to_numeric(&range->min_addr.in6));
if (memcmp(&range->min_addr, &range->max_addr,
sizeof(range->min_addr)))
- xt_buf_add(buf, "-%s",
+ xt_xlate_add(xl, "-%s",
xtables_ip6addr_to_numeric(&range->max_addr.in6));
}
if (range->flags & NF_NAT_RANGE_PROTO_SPECIFIED) {
- xt_buf_add(buf, " :%hu", ntohs(range->min_proto.tcp.port));
+ xt_xlate_add(xl, " :%hu", ntohs(range->min_proto.tcp.port));
if (range->max_proto.tcp.port != range->min_proto.tcp.port)
- xt_buf_add(buf, "-%hu",
+ xt_xlate_add(xl, "-%hu",
ntohs(range->max_proto.tcp.port));
}
}
static int DNAT_xlate(const struct xt_entry_target *target,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct nf_nat_range *range = (const void *)target->data;
bool sep_need = false;
const char *sep = " ";
- xt_buf_add(buf, "dnat ");
- print_range_xlate(range, buf);
+ xt_xlate_add(xl, "dnat ");
+ print_range_xlate(range, xl);
if (range->flags & NF_NAT_RANGE_PROTO_RANDOM) {
- xt_buf_add(buf, " random");
+ xt_xlate_add(xl, " random");
sep_need = true;
}
if (range->flags & NF_NAT_RANGE_PERSISTENT) {
if (sep_need)
sep = ",";
- xt_buf_add(buf, "%spersistent", sep);
+ xt_xlate_add(xl, "%spersistent", sep);
}
return 1;
};
static int LOG_xlate(const struct xt_entry_target *target,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
unsigned int i = 0;
const struct ip6t_log_info *loginfo =
(const struct ip6t_log_info *)target->data;
- xt_buf_add(buf, "log ");
+ xt_xlate_add(xl, "log ");
if (strcmp(loginfo->prefix, "") != 0)
- xt_buf_add(buf, "prefix \\\"%s\\\" ", loginfo->prefix);
+ xt_xlate_add(xl, "prefix \\\"%s\\\" ", loginfo->prefix);
for (i = 0; i < ARRAY_SIZE(ip6t_log_xlate_names); ++i)
if (loginfo->level == ip6t_log_xlate_names[i].level) {
- xt_buf_add(buf, "level %s",
+ xt_xlate_add(xl, "level %s",
ip6t_log_xlate_names[i].name);
break;
}
}
static int REDIRECT_xlate(const struct xt_entry_target *target,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct nf_nat_range *range = (const void *)target->data;
if (range->flags & NF_NAT_RANGE_PROTO_SPECIFIED) {
- xt_buf_add(buf, "redirect to %hu",
+ xt_xlate_add(xl, "redirect to %hu",
ntohs(range->min_proto.tcp.port));
if (range->max_proto.tcp.port != range->min_proto.tcp.port)
- xt_buf_add(buf, "-%hu ",
+ xt_xlate_add(xl, "-%hu ",
ntohs(range->max_proto.tcp.port));
if (range->flags & NF_NAT_RANGE_PROTO_RANDOM)
- xt_buf_add(buf, " random ");
+ xt_xlate_add(xl, " random ");
}
return 1;
};
static int REJECT_xlate(const struct xt_entry_target *target,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct ip6t_reject_info *reject =
(const struct ip6t_reject_info *)target->data;
if (reject_table_xlate[i].with == reject->with)
break;
if (reject->with == IP6T_TCP_RESET)
- xt_buf_add(buf, "reject with %s", reject_table_xlate[i].name);
+ xt_xlate_add(xl, "reject with %s", reject_table_xlate[i].name);
else
- xt_buf_add(buf, "reject with icmpv6 type %s",
+ xt_xlate_add(xl, "reject with icmpv6 type %s",
reject_table_xlate[i].name);
return 1;
}
static void print_range_xlate(const struct nf_nat_range *range,
- struct xt_buf *buf)
+ struct xt_xlate *xl)
{
if (range->flags & NF_NAT_RANGE_MAP_IPS) {
- xt_buf_add(buf, "%s",
+ xt_xlate_add(xl, "%s",
xtables_ip6addr_to_numeric(&range->min_addr.in6));
if (memcmp(&range->min_addr, &range->max_addr,
sizeof(range->min_addr)))
- xt_buf_add(buf, "-%s",
+ xt_xlate_add(xl, "-%s",
xtables_ip6addr_to_numeric(&range->max_addr.in6));
}
if (range->flags & NF_NAT_RANGE_PROTO_SPECIFIED) {
- xt_buf_add(buf, " :%hu", ntohs(range->min_proto.tcp.port));
+ xt_xlate_add(xl, " :%hu", ntohs(range->min_proto.tcp.port));
if (range->max_proto.tcp.port != range->min_proto.tcp.port)
- xt_buf_add(buf, "-%hu",
+ xt_xlate_add(xl, "-%hu",
ntohs(range->max_proto.tcp.port));
}
}
static int SNAT_xlate(const struct xt_entry_target *target,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct nf_nat_range *range = (const void *)target->data;
bool sep_need = false;
const char *sep = " ";
- xt_buf_add(buf, "snat ");
- print_range_xlate(range, buf);
+ xt_xlate_add(xl, "snat ");
+ print_range_xlate(range, xl);
if (range->flags & NF_NAT_RANGE_PROTO_RANDOM) {
- xt_buf_add(buf, " random");
+ xt_xlate_add(xl, " random");
sep_need = true;
}
if (range->flags & NF_NAT_RANGE_PROTO_RANDOM_FULLY) {
if (sep_need)
sep = ",";
- xt_buf_add(buf, "%sfully-random", sep);
+ xt_xlate_add(xl, "%sfully-random", sep);
sep_need = true;
}
if (range->flags & NF_NAT_RANGE_PERSISTENT) {
if (sep_need)
sep = ",";
- xt_buf_add(buf, "%spersistent", sep);
+ xt_xlate_add(xl, "%spersistent", sep);
}
return 1;
}
static int ah_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct ip6t_ah *ahinfo = (struct ip6t_ah *)match->data;
if (!(ahinfo->spis[0] == 0 && ahinfo->spis[1] == 0xFFFFFFFF)) {
- xt_buf_add(buf, "ah spi%s ",
+ xt_xlate_add(xl, "ah spi%s ",
(ahinfo->invflags & IP6T_AH_INV_SPI) ? " !=" : "");
if (ahinfo->spis[0] != ahinfo->spis[1])
- xt_buf_add(buf, "%u-%u ", ahinfo->spis[0], ahinfo->spis[1]);
+ xt_xlate_add(xl, "%u-%u ", ahinfo->spis[0], ahinfo->spis[1]);
else
- xt_buf_add(buf, "%u ", ahinfo->spis[0]);
+ xt_xlate_add(xl, "%u ", ahinfo->spis[0]);
}
if (ahinfo->hdrlen != 0 || (ahinfo->invflags & IP6T_AH_INV_LEN)) {
- xt_buf_add(buf, "ah hdrlength%s %u ",
+ xt_xlate_add(xl, "ah hdrlength%s %u ",
(ahinfo->invflags & IP6T_AH_INV_LEN) ? " !=" : "",
ahinfo->hdrlen);
}
if (ahinfo->hdrres != 0)
- xt_buf_add(buf, "ah reserved %u ", ahinfo->hdrres);
+ xt_xlate_add(xl, "ah reserved %u ", ahinfo->hdrres);
return 1;
}
}
static int hl_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
static const char *const op[] = {
[IP6T_HL_EQ] = "",
const struct ip6t_hl_info *info =
(struct ip6t_hl_info *) match->data;
- xt_buf_add(buf, "ip6 hoplimit %s%u ", op[info->mode], info->hop_limit);
+ xt_xlate_add(xl, "ip6 hoplimit %s%u ", op[info->mode], info->hop_limit);
return 1;
}
}
static void print_range_xlate(const struct nf_nat_ipv4_range *r,
- struct xt_buf *buf)
+ struct xt_xlate *xl)
{
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));
+ xt_xlate_add(xl, "%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));
+ xt_xlate_add(xl, "-%s", xtables_ipaddr_to_numeric(&a));
}
}
if (r->flags & NF_NAT_RANGE_PROTO_SPECIFIED) {
- xt_buf_add(buf, ":%hu", ntohs(r->min.tcp.port));
+ xt_xlate_add(xl, ":%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));
+ xt_xlate_add(xl, "-%hu", ntohs(r->max.tcp.port));
}
}
static int DNAT_xlate(const struct xt_entry_target *target,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct ipt_natinfo *info = (const void *)target;
unsigned int i = 0;
const char *sep = " ";
for (i = 0; i < info->mr.rangesize; i++) {
- xt_buf_add(buf, "dnat ");
- print_range_xlate(&info->mr.range[i], buf);
+ xt_xlate_add(xl, "dnat ");
+ print_range_xlate(&info->mr.range[i], xl);
if (info->mr.range[i].flags & NF_NAT_RANGE_PROTO_RANDOM) {
- xt_buf_add(buf, " random");
+ xt_xlate_add(xl, " random");
sep_need = true;
}
if (info->mr.range[i].flags & NF_NAT_RANGE_PERSISTENT) {
if (sep_need)
sep = ",";
- xt_buf_add(buf, "%spersistent", sep);
+ xt_xlate_add(xl, "%spersistent", sep);
}
}
};
static int LOG_xlate(const struct xt_entry_target *target,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
unsigned int i = 0;
const struct ipt_log_info *loginfo =
(const struct ipt_log_info *)target->data;
- xt_buf_add(buf, "log ");
+ xt_xlate_add(xl, "log ");
if (strcmp(loginfo->prefix, "") != 0)
- xt_buf_add(buf, "prefix \\\"%s\\\" ", loginfo->prefix);
+ xt_xlate_add(xl, "prefix \\\"%s\\\" ", loginfo->prefix);
for (i = 0; i < ARRAY_SIZE(ipt_log_xlate_names); ++i)
if (loginfo->level == ipt_log_xlate_names[i].level) {
- xt_buf_add(buf, "level %s ",
+ xt_xlate_add(xl, "level %s ",
ipt_log_xlate_names[i].name);
break;
}
}
static int REDIRECT_xlate(const struct xt_entry_target *target,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct nf_nat_ipv4_multi_range_compat *mr =
(const void *)target->data;
const struct nf_nat_ipv4_range *r = &mr->range[0];
if (r->flags & NF_NAT_RANGE_PROTO_SPECIFIED) {
- xt_buf_add(buf, "redirect to %hu", ntohs(r->min.tcp.port));
+ xt_xlate_add(xl, "redirect to %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));
+ xt_xlate_add(xl, "-%hu ", ntohs(r->max.tcp.port));
if (mr->range[0].flags & NF_NAT_RANGE_PROTO_RANDOM)
- xt_buf_add(buf, " random ");
+ xt_xlate_add(xl, " random ");
}
return 1;
};
static int REJECT_xlate(const struct xt_entry_target *target,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct ipt_reject_info *reject =
(const struct ipt_reject_info *)target->data;
}
if (reject->with == IPT_TCP_RESET)
- xt_buf_add(buf, "reject with %s",
+ xt_xlate_add(xl, "reject with %s",
reject_table_xlate[i].name);
else
- xt_buf_add(buf, "reject with icmp type %s",
+ xt_xlate_add(xl, "reject with icmp type %s",
reject_table_xlate[i].name);
return 1;
}
static void print_range_xlate(const struct nf_nat_ipv4_range *r,
- struct xt_buf *buf)
+ struct xt_xlate *xl)
{
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));
+ xt_xlate_add(xl, "%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));
+ xt_xlate_add(xl, "-%s", xtables_ipaddr_to_numeric(&a));
}
}
if (r->flags & NF_NAT_RANGE_PROTO_SPECIFIED) {
- xt_buf_add(buf, ":");
- xt_buf_add(buf, "%hu", ntohs(r->min.tcp.port));
+ xt_xlate_add(xl, ":");
+ xt_xlate_add(xl, "%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));
+ xt_xlate_add(xl, "-%hu", ntohs(r->max.tcp.port));
}
}
static int SNAT_xlate(const struct xt_entry_target *target,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct ipt_natinfo *info = (const void *)target;
unsigned int i = 0;
const char *sep = " ";
for (i = 0; i < info->mr.rangesize; i++) {
- xt_buf_add(buf, "snat ");
- print_range_xlate(&info->mr.range[i], buf);
+ xt_xlate_add(xl, "snat ");
+ print_range_xlate(&info->mr.range[i], xl);
if (info->mr.range[i].flags & NF_NAT_RANGE_PROTO_RANDOM) {
- xt_buf_add(buf, " random");
+ xt_xlate_add(xl, " random");
sep_need = true;
}
if (info->mr.range[i].flags & NF_NAT_RANGE_PROTO_RANDOM_FULLY) {
if (sep_need)
sep = ",";
- xt_buf_add(buf, "%sfully-random", sep);
+ xt_xlate_add(xl, "%sfully-random", sep);
sep_need = true;
}
if (info->mr.range[i].flags & NF_NAT_RANGE_PERSISTENT) {
if (sep_need)
sep = ",";
- xt_buf_add(buf, "%spersistent", sep);
+ xt_xlate_add(xl, "%spersistent", sep);
}
}
}
static int ah_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct ipt_ah *ahinfo = (struct ipt_ah *)match->data;
if (!(ahinfo->spis[0] == 0 && ahinfo->spis[1] == 0xFFFFFFFF)) {
- xt_buf_add(buf, "ah spi%s ",
+ xt_xlate_add(xl, "ah spi%s ",
(ahinfo->invflags & IPT_AH_INV_SPI) ? " !=" : "");
if (ahinfo->spis[0] != ahinfo->spis[1])
- xt_buf_add(buf, "%u-%u ", ahinfo->spis[0],
+ xt_xlate_add(xl, "%u-%u ", ahinfo->spis[0],
ahinfo->spis[1]);
else
- xt_buf_add(buf, "%u ", ahinfo->spis[0]);
+ xt_xlate_add(xl, "%u ", ahinfo->spis[0]);
}
return 1;
static void
print_realm_xlate(unsigned long id, unsigned long mask,
- int numeric, struct xt_buf *buf, uint32_t op)
+ int numeric, struct xt_xlate *xl, uint32_t op)
{
const char *name = NULL;
if (mask != 0xffffffff)
- xt_buf_add(buf, " and 0x%lx %s 0x%lx ", id,
+ xt_xlate_add(xl, " and 0x%lx %s 0x%lx ", id,
op == XT_OP_EQ ? "==" : "!=", mask);
else {
if (numeric == 0)
name = xtables_lmap_id2name(realms, id);
if (name)
- xt_buf_add(buf, "%s%s ",
+ xt_xlate_add(xl, "%s%s ",
op == XT_OP_EQ ? "" : "!= ", name);
else
- xt_buf_add(buf, " %s0x%lx ",
+ xt_xlate_add(xl, " %s0x%lx ",
op == XT_OP_EQ ? "" : "!= ", id);
}
}
static int realm_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct xt_realm_info *ri = (const void *)match->data;
enum xt_op op = XT_OP_EQ;
if (ri->invert)
op = XT_OP_NEQ;
- xt_buf_add(buf, "rtclassid");
- print_realm_xlate(ri->id, ri->mask, 0, buf, op);
+ xt_xlate_add(xl, "rtclassid");
+ print_realm_xlate(ri->id, ri->mask, 0, xl, op);
return 1;
}
}
static int ttl_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct ipt_ttl_info *info =
(struct ipt_ttl_info *) match->data;
switch (info->mode) {
case IPT_TTL_EQ:
- xt_buf_add(buf, "ip ttl");
+ xt_xlate_add(xl, "ip ttl");
break;
case IPT_TTL_NE:
- xt_buf_add(buf, "ip ttl !=");
+ xt_xlate_add(xl, "ip ttl !=");
break;
case IPT_TTL_LT:
- xt_buf_add(buf, "ip ttl lt");
+ xt_xlate_add(xl, "ip ttl lt");
break;
case IPT_TTL_GT:
- xt_buf_add(buf, "ip ttl gt");
+ xt_xlate_add(xl, "ip ttl gt");
break;
default:
/* Should not happen. */
break;
}
- xt_buf_add(buf, " %u ", info->ttl);
+ xt_xlate_add(xl, " %u ", info->ttl);
return 1;
}
}
static void nflog_print_xlate(const struct xt_nflog_info *info,
- struct xt_buf *buf)
+ struct xt_xlate *xl)
{
- xt_buf_add(buf, "log ");
+ xt_xlate_add(xl, "log ");
if (info->prefix[0] != '\0')
- xt_buf_add(buf, "prefix \\\"%s\\\" ", info->prefix);
+ xt_xlate_add(xl, "prefix \\\"%s\\\" ", info->prefix);
if (info->len)
- xt_buf_add(buf, "snaplen %u ", info->len);
+ xt_xlate_add(xl, "snaplen %u ", info->len);
if (info->threshold != XT_NFLOG_DEFAULT_THRESHOLD)
- xt_buf_add(buf, "queue-threshold %u ", info->threshold);
- xt_buf_add(buf, "group %u ", info->group);
+ xt_xlate_add(xl, "queue-threshold %u ", info->threshold);
+ xt_xlate_add(xl, "group %u ", info->group);
}
static int NFLOG_xlate(const struct xt_entry_target *target,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct xt_nflog_info *info = (struct xt_nflog_info *)target->data;
- nflog_print_xlate(info, buf);
+ nflog_print_xlate(info, xl);
return 1;
}
}
static void print_mark_xlate(unsigned int mark, unsigned int mask,
- struct xt_buf *buf, uint32_t op)
+ struct xt_xlate *xl, uint32_t op)
{
if (mask != 0xffffffffU)
- xt_buf_add(buf, " and 0x%x %s 0x%x ", mark,
+ xt_xlate_add(xl, " and 0x%x %s 0x%x ", mark,
op == XT_OP_EQ ? "==" : "!=", mask);
else
- xt_buf_add(buf, " %s0x%x ",
+ xt_xlate_add(xl, " %s0x%x ",
op == XT_OP_EQ ? "" : "!= ", mark);
}
static int connmark_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct xt_connmark_info *info = (const void *)match->data;
enum xt_op op = XT_OP_EQ;
if (info->invert)
op = XT_OP_NEQ;
- xt_buf_add(buf, "ct mark");
- print_mark_xlate(info->mark, info->mask, buf, op);
+ xt_xlate_add(xl, "ct mark");
+ print_mark_xlate(info->mark, info->mask, xl, op);
return 1;
}
static int
connmark_mt_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct xt_connmark_mtinfo1 *info = (const void *)match->data;
enum xt_op op = XT_OP_EQ;
if (info->invert)
op = XT_OP_NEQ;
- xt_buf_add(buf, "ct mark");
- print_mark_xlate(info->mark, info->mask, buf, op);
+ xt_xlate_add(xl, "ct mark");
+ print_mark_xlate(info->mark, info->mask, xl, op);
return 1;
}
state_print_state(sinfo->statemask);
}
-static void state_xlate_print(struct xt_buf *buf, unsigned int statemask)
+static void state_xlate_print(struct xt_xlate *xl, unsigned int statemask)
{
const char *sep = "";
if (statemask & XT_CONNTRACK_STATE_INVALID) {
- xt_buf_add(buf, "%s%s", sep, "invalid");
+ xt_xlate_add(xl, "%s%s", sep, "invalid");
sep = ",";
}
if (statemask & XT_CONNTRACK_STATE_BIT(IP_CT_NEW)) {
- xt_buf_add(buf, "%s%s", sep, "new");
+ xt_xlate_add(xl, "%s%s", sep, "new");
sep = ",";
}
if (statemask & XT_CONNTRACK_STATE_BIT(IP_CT_RELATED)) {
- xt_buf_add(buf, "%s%s", sep, "related");
+ xt_xlate_add(xl, "%s%s", sep, "related");
sep = ",";
}
if (statemask & XT_CONNTRACK_STATE_BIT(IP_CT_ESTABLISHED)) {
- xt_buf_add(buf, "%s%s", sep, "established");
+ xt_xlate_add(xl, "%s%s", sep, "established");
sep = ",";
}
if (statemask & XT_CONNTRACK_STATE_UNTRACKED) {
- xt_buf_add(buf, "%s%s", sep, "untracked");
+ xt_xlate_add(xl, "%s%s", sep, "untracked");
sep = ",";
}
}
-static int state_xlate(const struct xt_entry_match *match, struct xt_buf *buf,
+static int state_xlate(const struct xt_entry_match *match, struct xt_xlate *xl,
int numeric)
{
const struct xt_conntrack_mtinfo3 *sinfo = (const void *)match->data;
- xt_buf_add(buf, "ct state %s", sinfo->invert_flags & XT_CONNTRACK_STATE ?
+ xt_xlate_add(xl, "ct state %s", sinfo->invert_flags & XT_CONNTRACK_STATE ?
"!= " : "");
- state_xlate_print(buf, sinfo->state_mask);
- xt_buf_add(buf, " ");
+ state_xlate_print(xl, sinfo->state_mask);
+ xt_xlate_add(xl, " ");
return 1;
}
}
static int cpu_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct xt_cpu_info *info = (void *)match->data;
- xt_buf_add(buf, "cpu%s %u ", info->invert ? " !=" : "", info->cpu);
+ xt_xlate_add(xl, "cpu%s %u ", info->invert ? " !=" : "", info->cpu);
return 1;
}
static void
print_devgroup_xlate(unsigned int id, uint32_t op, unsigned int mask,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const char *name = NULL;
if (mask != 0xffffffff)
- xt_buf_add(buf, "and 0x%x %s 0x%x ", id,
+ xt_xlate_add(xl, "and 0x%x %s 0x%x ", id,
op == XT_OP_EQ ? "==" : "!=", mask);
else {
if (numeric == 0)
name = xtables_lmap_id2name(devgroups, id);
if (name)
- xt_buf_add(buf, "%s ", name);
+ xt_xlate_add(xl, "%s ", name);
else
- xt_buf_add(buf, "%s0x%x ",
+ xt_xlate_add(xl, "%s0x%x ",
op == XT_OP_EQ ? "" : "!= ", id);
}
}
static void devgroup_show_xlate(const struct xt_devgroup_info *info,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
enum xt_op op = XT_OP_EQ;
if (info->flags & XT_DEVGROUP_MATCH_SRC) {
if (info->flags & XT_DEVGROUP_INVERT_SRC)
op = XT_OP_NEQ;
- xt_buf_add(buf, "iifgroup ");
+ xt_xlate_add(xl, "iifgroup ");
print_devgroup_xlate(info->src_group, op,
- info->src_mask, buf, numeric);
+ info->src_mask, xl, numeric);
}
if (info->flags & XT_DEVGROUP_MATCH_DST) {
if (info->flags & XT_DEVGROUP_INVERT_DST)
op = XT_OP_NEQ;
- xt_buf_add(buf, "oifgroup ");
+ xt_xlate_add(xl, "oifgroup ");
print_devgroup_xlate(info->dst_group, op,
- info->dst_mask, buf, numeric);
+ info->dst_mask, xl, numeric);
}
}
static int devgroup_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct xt_devgroup_info *info = (const void *)match->data;
- devgroup_show_xlate(info, buf, 0);
+ devgroup_show_xlate(info, xl, 0);
return 1;
}
}
static int esp_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct xt_esp *espinfo = (struct xt_esp *)match->data;
if (!(espinfo->spis[0] == 0 && espinfo->spis[1] == 0xFFFFFFFF)) {
- xt_buf_add(buf, "esp spi%s",
+ xt_xlate_add(xl, "esp spi%s",
(espinfo->invflags & XT_ESP_INV_SPI) ? " !=" : "");
if (espinfo->spis[0] != espinfo->spis[1])
- xt_buf_add(buf, " %u-%u ", espinfo->spis[0],
+ xt_xlate_add(xl, " %u-%u ", espinfo->spis[0],
espinfo->spis[1]);
else
- xt_buf_add(buf, " %u ", espinfo->spis[0]);
+ xt_xlate_add(xl, " %u ", espinfo->spis[0]);
}
return 1;
}
static int helper_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct xt_helper_info *info = (const void *)match->data;
- xt_buf_add(buf, "ct helper%s \\\"%s\\\" ",
+ xt_xlate_add(xl, "ct helper%s \\\"%s\\\" ",
info->invert ? " !=" : "", info->name);
return 1;
static void
print_iprange_xlate(const struct ipt_iprange *range,
- struct xt_buf *buf)
+ struct xt_xlate *xl)
{
const unsigned char *byte_min, *byte_max;
byte_min = (const unsigned char *)&range->min_ip;
byte_max = (const unsigned char *)&range->max_ip;
- xt_buf_add(buf, " %u.%u.%u.%u-%u.%u.%u.%u ",
+ xt_xlate_add(xl, " %u.%u.%u.%u-%u.%u.%u.%u ",
byte_min[0], byte_min[1], byte_min[2], byte_min[3],
byte_max[0], byte_max[1], byte_max[2], byte_max[3]);
}
static int iprange_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct ipt_iprange_info *info = (const void *)match->data;
if (info->flags & IPRANGE_SRC) {
if (info->flags & IPRANGE_SRC_INV)
- xt_buf_add(buf, " !=");
- xt_buf_add(buf, " ip saddr");
- print_iprange_xlate(&info->src, buf);
+ xt_xlate_add(xl, " !=");
+ xt_xlate_add(xl, " ip saddr");
+ print_iprange_xlate(&info->src, xl);
}
if (info->flags & IPRANGE_DST) {
if (info->flags & IPRANGE_DST_INV)
- xt_buf_add(buf, " !=");
- xt_buf_add(buf, " ip daddr");
- print_iprange_xlate(&info->dst, buf);
+ xt_xlate_add(xl, " !=");
+ xt_xlate_add(xl, " ip daddr");
+ print_iprange_xlate(&info->dst, xl);
}
return 1;
}
static int iprange_mt4_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct xt_iprange_mtinfo *info = (const void *)match->data;
if (info->flags & IPRANGE_SRC) {
if (info->flags & IPRANGE_SRC_INV)
- xt_buf_add(buf, " !=");
- xt_buf_add(buf, " ip saddr %s",
+ xt_xlate_add(xl, " !=");
+ xt_xlate_add(xl, " ip saddr %s",
xtables_ipaddr_to_numeric(&info->src_min.in));
- xt_buf_add(buf, "-%s ",
+ xt_xlate_add(xl, "-%s ",
xtables_ipaddr_to_numeric(&info->src_max.in));
}
if (info->flags & IPRANGE_DST) {
if (info->flags & IPRANGE_DST_INV)
- xt_buf_add(buf, " !=");
- xt_buf_add(buf, " ip daddr %s",
+ xt_xlate_add(xl, " !=");
+ xt_xlate_add(xl, " ip daddr %s",
xtables_ipaddr_to_numeric(&info->dst_min.in));
- xt_buf_add(buf, "-%s ",
+ xt_xlate_add(xl, "-%s ",
xtables_ipaddr_to_numeric(&info->dst_max.in));
}
}
static int iprange_mt6_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct xt_iprange_mtinfo *info = (const void *)match->data;
if (info->flags & IPRANGE_SRC) {
if (info->flags & IPRANGE_SRC_INV)
- xt_buf_add(buf, " !=");
- xt_buf_add(buf, " ip saddr %s",
+ xt_xlate_add(xl, " !=");
+ xt_xlate_add(xl, " ip saddr %s",
xtables_ip6addr_to_numeric(&info->src_min.in6));
- xt_buf_add(buf, "-%s ",
+ xt_xlate_add(xl, "-%s ",
xtables_ip6addr_to_numeric(&info->src_max.in6));
}
if (info->flags & IPRANGE_DST) {
if (info->flags & IPRANGE_DST_INV)
- xt_buf_add(buf, " !=");
- xt_buf_add(buf, " ip daddr %s",
+ xt_xlate_add(xl, " !=");
+ xt_xlate_add(xl, " ip daddr %s",
xtables_ip6addr_to_numeric(&info->dst_min.in6));
- xt_buf_add(buf, "-%s ",
+ xt_xlate_add(xl, "-%s ",
xtables_ip6addr_to_numeric(&info->dst_max.in6));
}
}
static int length_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct xt_length_info *info = (void *)match->data;
- xt_buf_add(buf, "meta length %s", info->invert ? "!= " : "");
+ xt_xlate_add(xl, "meta length %s", info->invert ? "!= " : "");
if (info->min == info->max)
- xt_buf_add(buf, "%u ", info->min);
+ xt_xlate_add(xl, "%u ", info->min);
else
- xt_buf_add(buf, "%u-%u ", info->min, info->max);
+ xt_xlate_add(xl, "%u-%u ", info->min, info->max);
return 1;
}
{ "second", XT_LIMIT_SCALE }
};
-static void print_rate_xlate(uint32_t period, struct xt_buf *buf)
+static void print_rate_xlate(uint32_t period, struct xt_xlate *xl)
{
unsigned int i;
if (period == 0) {
- xt_buf_add(buf, " %f ", INFINITY);
+ xt_xlate_add(xl, " %f ", INFINITY);
return;
}
rates_xlate[i].mult / period < rates_xlate[i].mult % period)
break;
- xt_buf_add(buf, " %u/%s ", rates_xlate[i - 1].mult / period,
+ xt_xlate_add(xl, " %u/%s ", rates_xlate[i - 1].mult / period,
rates_xlate[i - 1].name);
}
static int limit_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct xt_rateinfo *r = (const void *)match->data;
- xt_buf_add(buf, "limit rate");
- print_rate_xlate(r->avg, buf);
+ xt_xlate_add(xl, "limit rate");
+ print_rate_xlate(r->avg, xl);
if (r->burst != XT_LIMIT_BURST)
- xt_buf_add(buf, "burst %u packets ", r->burst);
+ xt_xlate_add(xl, "burst %u packets ", r->burst);
return 1;
}
}
static void print_mac_xlate(const unsigned char *macaddress,
- struct xt_buf *buf)
+ struct xt_xlate *xl)
{
unsigned int i;
- xt_buf_add(buf, "%02x", macaddress[0]);
+ xt_xlate_add(xl, "%02x", macaddress[0]);
for (i = 1; i < ETH_ALEN; ++i)
- xt_buf_add(buf, ":%02x", macaddress[i]);
- xt_buf_add(buf, " ");
+ xt_xlate_add(xl, ":%02x", macaddress[i]);
+ xt_xlate_add(xl, " ");
}
static int mac_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct xt_mac_info *info = (void *)match->data;
- xt_buf_add(buf, "ether saddr%s ", info->invert ? " !=" : "");
- print_mac_xlate(info->srcaddr, buf);
+ xt_xlate_add(xl, "ether saddr%s ", info->invert ? " !=" : "");
+ print_mac_xlate(info->srcaddr, xl);
return 1;
}
}
static void
-print_mark_xlate(struct xt_buf *buf, unsigned int mark,
+print_mark_xlate(struct xt_xlate *xl, unsigned int mark,
unsigned int mask, uint32_t op)
{
if (mask != 0xffffffffU)
- xt_buf_add(buf, " and 0x%x %s 0x%x ", mark,
+ xt_xlate_add(xl, " and 0x%x %s 0x%x ", mark,
op == XT_OP_EQ ? "==" : "!=", mask);
else
- xt_buf_add(buf, " %s0x%x ",
+ xt_xlate_add(xl, " %s0x%x ",
op == XT_OP_EQ ? "" : "!= ", mark);
}
static int
mark_mt_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct xt_mark_mtinfo1 *info = (const void *)match->data;
enum xt_op op = XT_OP_EQ;
if (info->invert)
op = XT_OP_NEQ;
- xt_buf_add(buf, "mark");
- print_mark_xlate(buf, info->mark, info->mask, op);
+ xt_xlate_add(xl, "mark");
+ print_mark_xlate(xl, info->mark, info->mask, op);
return 1;
}
static int
mark_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct xt_mark_info *info = (const void *)match->data;
enum xt_op op = XT_OP_EQ;
if (info->invert)
op = XT_OP_NEQ;
- xt_buf_add(buf, "mark");
- print_mark_xlate(buf, info->mark, info->mask, op);
+ xt_xlate_add(xl, "mark");
+ print_mark_xlate(xl, info->mark, info->mask, op);
return 1;
}
};
static void print_pkttype_xlate(const struct xt_pkttype_info *info,
- struct xt_buf *buf)
+ struct xt_xlate *xl)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(supported_types_xlate); ++i) {
if (supported_types_xlate[i].pkttype == info->pkttype) {
- xt_buf_add(buf, "%s ", supported_types_xlate[i].name);
+ xt_xlate_add(xl, "%s ", supported_types_xlate[i].name);
return;
}
}
- xt_buf_add(buf, "%d", info->pkttype);
+ xt_xlate_add(xl, "%d", info->pkttype);
}
static int pkttype_xlate(const struct xt_entry_match *match,
- struct xt_buf *buf, int numeric)
+ struct xt_xlate *xl, int numeric)
{
const struct xt_pkttype_info *info = (const void *)match->data;
- xt_buf_add(buf, "pkttype%s ", info->invert ? " !=" : "");
- print_pkttype_xlate(info, buf);
+ xt_xlate_add(xl, "pkttype%s ", info->invert ? " !=" : "");
+ print_pkttype_xlate(info, xl);
return 1;
}
{ "urg", 0x20 },
};
-static void print_tcp_xlate(struct xt_buf *buf, uint8_t flags)
+static void print_tcp_xlate(struct xt_xlate *xl, uint8_t flags)
{
int have_flag = 0;
for (i = 0; (flags & tcp_flag_names_xlate[i].flag) == 0; i++);
if (have_flag)
- xt_buf_add(buf, "|");
+ xt_xlate_add(xl, "|");
- xt_buf_add(buf, "%s", tcp_flag_names_xlate[i].name);
+ xt_xlate_add(xl, "%s", tcp_flag_names_xlate[i].name);
have_flag = 1;
flags &= ~tcp_flag_names_xlate[i].flag;
}
if (!have_flag)
- xt_buf_add(buf, "none");
+ xt_xlate_add(xl, "none");
}
-static int tcp_xlate(const struct xt_entry_match *match, struct xt_buf *buf,
+static int tcp_xlate(const struct xt_entry_match *match, struct xt_xlate *xl,
int numeric)
{
const struct xt_tcp *tcpinfo = (const struct xt_tcp *)match->data;
if (tcpinfo->spts[0] != 0 || tcpinfo->spts[1] != 0xffff) {
if (tcpinfo->spts[0] != tcpinfo->spts[1]) {
- xt_buf_add(buf, "tcp sport %s%u-%u ",
+ xt_xlate_add(xl, "tcp sport %s%u-%u ",
tcpinfo->invflags & XT_TCP_INV_SRCPT ?
"!= " : "",
tcpinfo->spts[0], tcpinfo->spts[1]);
} else {
- xt_buf_add(buf, "tcp sport %s%u ",
+ xt_xlate_add(xl, "tcp sport %s%u ",
tcpinfo->invflags & XT_TCP_INV_SRCPT ?
"!= " : "",
tcpinfo->spts[0]);
if (tcpinfo->dpts[0] != 0 || tcpinfo->dpts[1] != 0xffff) {
if (tcpinfo->dpts[0] != tcpinfo->dpts[1]) {
- xt_buf_add(buf, "tcp dport %s%u-%u ",
+ xt_xlate_add(xl, "tcp dport %s%u-%u ",
tcpinfo->invflags & XT_TCP_INV_DSTPT ?
"!= " : "",
tcpinfo->dpts[0], tcpinfo->dpts[1]);
} else {
- xt_buf_add(buf, "tcp dport %s%u ",
+ xt_xlate_add(xl, "tcp dport %s%u ",
tcpinfo->invflags & XT_TCP_INV_DSTPT ?
"!= " : "",
tcpinfo->dpts[0]);
return 0;
if (tcpinfo->flg_mask || (tcpinfo->invflags & XT_TCP_INV_FLAGS)) {
- xt_buf_add(buf, "tcp flags & ");
- print_tcp_xlate(buf, tcpinfo->flg_mask);
- xt_buf_add(buf, " %s ",
+ xt_xlate_add(xl, "tcp flags & ");
+ print_tcp_xlate(xl, tcpinfo->flg_mask);
+ xt_xlate_add(xl, " %s ",
tcpinfo->invflags & XT_TCP_INV_FLAGS ? "!=": "==");
- print_tcp_xlate(buf, tcpinfo->flg_cmp);
- xt_buf_add(buf, " ");
+ print_tcp_xlate(xl, tcpinfo->flg_cmp);
+ xt_xlate_add(xl, " ");
}
return 1;
}
}
-static int udp_xlate(const struct xt_entry_match *match, struct xt_buf *buf,
+static int udp_xlate(const struct xt_entry_match *match, struct xt_xlate *xl,
int numeric)
{
const struct xt_udp *udpinfo = (struct xt_udp *)match->data;
if (udpinfo->spts[0] != 0 || udpinfo->spts[1] != 0xFFFF) {
if (udpinfo->spts[0] != udpinfo->spts[1]) {
- xt_buf_add(buf,"udp sport %s%u-%u ",
+ xt_xlate_add(xl,"udp sport %s%u-%u ",
udpinfo->invflags & XT_UDP_INV_SRCPT ?
"!= ": "",
udpinfo->spts[0], udpinfo->spts[1]);
} else {
- xt_buf_add(buf, "udp sport %s%u ",
+ xt_xlate_add(xl, "udp sport %s%u ",
udpinfo->invflags & XT_UDP_INV_SRCPT ?
"!= ": "",
udpinfo->spts[0]);
if (udpinfo->dpts[0] != 0 || udpinfo->dpts[1] != 0xFFFF) {
if (udpinfo->dpts[0] != udpinfo->dpts[1]) {
- xt_buf_add(buf,"udp dport %s%u-%u ",
+ xt_xlate_add(xl,"udp dport %s%u-%u ",
udpinfo->invflags & XT_UDP_INV_SRCPT ?
"!= ": "",
udpinfo->dpts[0], udpinfo->dpts[1]);
} else {
- xt_buf_add(buf,"udp dport %s%u ",
+ xt_xlate_add(xl,"udp dport %s%u ",
udpinfo->invflags & XT_UDP_INV_SRCPT ?
"!= ": "",
udpinfo->dpts[0]);
XTABLES_EXT_ALIAS = 1 << 0,
};
-struct xt_buf;
+struct xt_xlate;
/* Include file for additions: new matches and targets. */
struct xtables_match
const struct xt_option_entry *x6_options;
/* Translate iptables to nft */
- int (*xlate)(const struct xt_entry_match *match, struct xt_buf *buf,
+ int (*xlate)(const struct xt_entry_match *match, struct xt_xlate *xl,
int numeric);
/* Size of per-extension instance extra "global" scratch space */
const struct xt_option_entry *x6_options;
/* Translate iptables to nft */
- int (*xlate)(const struct xt_entry_target *target, struct xt_buf *buf,
+ int (*xlate)(const struct xt_entry_target *target, struct xt_xlate *xl,
int numeric);
size_t udata_size;
extern int xtables_lmap_name2id(const struct xtables_lmap *, const char *);
extern const char *xtables_lmap_id2name(const struct xtables_lmap *, int);
-/* generic buffer */
-struct xt_buf *xt_buf_alloc(int size);
-void xt_buf_free(struct xt_buf *buf);
-void xt_buf_add(struct xt_buf *buf, const char *fmt, ...);
-const char *xt_buf_get(struct xt_buf *buf);
+/* xlate infrastructure */
+struct xt_xlate *xt_xlate_alloc(int size);
+void xt_xlate_free(struct xt_xlate *xl);
+void xt_xlate_add(struct xt_xlate *xl, const char *fmt, ...);
+const char *xt_xlate_get(struct xt_xlate *xl);
#ifdef XTABLES_INTERNAL
save_counters(cs->counters.pcnt, cs->counters.bcnt);
}
-static int nft_ipv4_xlate(const void *data, struct xt_buf *buf)
+static int nft_ipv4_xlate(const void *data, struct xt_xlate *xl)
{
const struct iptables_command_state *cs = data;
int ret;
if (cs->fw.ip.iniface[0] != '\0') {
- xt_buf_add(buf, "iifname %s%s ",
+ xt_xlate_add(xl, "iifname %s%s ",
cs->fw.ip.invflags & IPT_INV_VIA_IN ? "!= " : "",
cs->fw.ip.iniface);
}
if (cs->fw.ip.outiface[0] != '\0') {
- xt_buf_add(buf, "oifname %s%s ",
+ xt_xlate_add(xl, "oifname %s%s ",
cs->fw.ip.invflags & IPT_INV_VIA_OUT? "!= " : "",
cs->fw.ip.outiface);
}
if (cs->fw.ip.flags & IPT_F_FRAG) {
- xt_buf_add(buf, "ip frag-off %s%x ",
+ xt_xlate_add(xl, "ip frag-off %s%x ",
cs->fw.ip.invflags & IPT_INV_FRAG? "" : "!= ", 0);
}
snprintf(protonum, sizeof(protonum), "%u",
cs->fw.ip.proto);
protonum[sizeof(protonum) - 1] = '\0';
- xt_buf_add(buf, "ip protocol %s%s ",
+ xt_xlate_add(xl, "ip protocol %s%s ",
cs->fw.ip.invflags & IPT_INV_PROTO ?
"!= " : "",
pent ? pent->p_name : protonum);
}
if (cs->fw.ip.src.s_addr != 0) {
- xt_buf_add(buf, "ip saddr %s%s ",
+ xt_xlate_add(xl, "ip saddr %s%s ",
cs->fw.ip.invflags & IPT_INV_SRCIP ? "!= " : "",
inet_ntoa(cs->fw.ip.src));
}
if (cs->fw.ip.dst.s_addr != 0) {
- xt_buf_add(buf, "ip daddr %s%s ",
+ xt_xlate_add(xl, "ip daddr %s%s ",
cs->fw.ip.invflags & IPT_INV_DSTIP ? "!= " : "",
inet_ntoa(cs->fw.ip.dst));
}
- ret = xlate_matches(cs, buf);
+ ret = xlate_matches(cs, xl);
if (!ret)
return ret;
/* Always add counters per rule, as in iptables */
- xt_buf_add(buf, "counter ");
+ xt_xlate_add(xl, "counter ");
- ret = xlate_action(cs, !!(cs->fw.ip.flags & IPT_F_GOTO), buf);
+ ret = xlate_action(cs, !!(cs->fw.ip.flags & IPT_F_GOTO), xl);
return ret;
}
}
static void xlate_ipv6_addr(const char *selector, const struct in6_addr *addr,
- int invert, struct xt_buf *buf)
+ int invert, struct xt_xlate *xl)
{
char addr_str[INET6_ADDRSTRLEN];
return;
inet_ntop(AF_INET6, addr, addr_str, INET6_ADDRSTRLEN);
- xt_buf_add(buf, "%s %s%s ", selector, invert ? "!= " : "", addr_str);
+ xt_xlate_add(xl, "%s %s%s ", selector, invert ? "!= " : "", addr_str);
}
-static int nft_ipv6_xlate(const void *data, struct xt_buf *buf)
+static int nft_ipv6_xlate(const void *data, struct xt_xlate *xl)
{
const struct iptables_command_state *cs = data;
int ret;
if (cs->fw6.ipv6.iniface[0] != '\0') {
- xt_buf_add(buf, "iifname %s%s ",
+ xt_xlate_add(xl, "iifname %s%s ",
cs->fw6.ipv6.invflags & IP6T_INV_VIA_IN ?
"!= " : "",
cs->fw6.ipv6.iniface);
}
if (cs->fw6.ipv6.outiface[0] != '\0') {
- xt_buf_add(buf, "oifname %s%s ",
+ xt_xlate_add(xl, "oifname %s%s ",
cs->fw6.ipv6.invflags & IP6T_INV_VIA_OUT ?
"!= " : "",
cs->fw6.ipv6.outiface);
snprintf(protonum, sizeof(protonum), "%u",
cs->fw6.ipv6.proto);
protonum[sizeof(protonum) - 1] = '\0';
- xt_buf_add(buf, "ip6 nexthdr %s%s ",
+ xt_xlate_add(xl, "ip6 nexthdr %s%s ",
cs->fw6.ipv6.invflags & IP6T_INV_PROTO ?
"!= " : "",
pent ? pent->p_name : protonum);
}
xlate_ipv6_addr("ip6 saddr", &cs->fw6.ipv6.src,
- cs->fw6.ipv6.invflags & IP6T_INV_SRCIP, buf);
+ cs->fw6.ipv6.invflags & IP6T_INV_SRCIP, xl);
xlate_ipv6_addr("ip6 daddr", &cs->fw6.ipv6.dst,
- cs->fw6.ipv6.invflags & IP6T_INV_DSTIP, buf);
+ cs->fw6.ipv6.invflags & IP6T_INV_DSTIP, xl);
- ret = xlate_matches(cs, buf);
+ ret = xlate_matches(cs, xl);
if (!ret)
return ret;
/* Always add counters per rule, as in iptables */
- xt_buf_add(buf, "counter ");
+ xt_xlate_add(xl, "counter ");
- ret = xlate_action(cs, !!(cs->fw6.ipv6.flags & IP6T_F_GOTO), buf);
+ ret = xlate_action(cs, !!(cs->fw6.ipv6.flags & IP6T_F_GOTO), xl);
return ret;
}
#define FMT(tab,notab) ((format) & FMT_NOTABLE ? (notab) : (tab))
struct xtables_args;
-struct xt_buf;
+struct xt_xlate;
enum {
NFT_XT_CTX_PAYLOAD = (1 << 0),
void (*parse_target)(struct xtables_target *t, void *data);
bool (*rule_find)(struct nft_family_ops *ops, struct nftnl_rule *r,
void *data);
- int (*xlate)(const void *data, struct xt_buf *buf);
+ int (*xlate)(const void *data, struct xt_xlate *xl);
};
void add_meta(struct nftnl_rule *r, uint32_t key);
struct xt_buf;
bool xlate_find_match(const struct iptables_command_state *cs, const char *p_name);
-int xlate_matches(const struct iptables_command_state *cs, struct xt_buf *buf);
+int xlate_matches(const struct iptables_command_state *cs, struct xt_xlate *xl);
int xlate_action(const struct iptables_command_state *cs, bool goto_set,
- struct xt_buf *buf);
+ struct xt_xlate *xl);
/*
* ARP
#include "nft-shared.h"
int xlate_action(const struct iptables_command_state *cs, bool goto_set,
- struct xt_buf *buf)
+ struct xt_xlate *xl)
{
int ret = 1, numeric = cs->options & OPT_NUMERIC;
if (cs->target != NULL) {
/* Standard target? */
if (strcmp(cs->jumpto, XTC_LABEL_ACCEPT) == 0)
- xt_buf_add(buf, "accept");
+ xt_xlate_add(xl, "accept");
else if (strcmp(cs->jumpto, XTC_LABEL_DROP) == 0)
- xt_buf_add(buf, "drop");
+ xt_xlate_add(xl, "drop");
else if (strcmp(cs->jumpto, XTC_LABEL_RETURN) == 0)
- xt_buf_add(buf, "return");
+ xt_xlate_add(xl, "return");
else if (cs->target->xlate)
- ret = cs->target->xlate(cs->target->t, buf, numeric);
+ ret = cs->target->xlate(cs->target->t, xl, numeric);
else
return 0;
} else if (strlen(cs->jumpto) > 0) {
/* Not standard, then it's a go / jump to chain */
if (goto_set)
- xt_buf_add(buf, "goto %s", cs->jumpto);
+ xt_xlate_add(xl, "goto %s", cs->jumpto);
else
- xt_buf_add(buf, "jump %s", cs->jumpto);
+ xt_xlate_add(xl, "jump %s", cs->jumpto);
}
return ret;
}
-int xlate_matches(const struct iptables_command_state *cs, struct xt_buf *buf)
+int xlate_matches(const struct iptables_command_state *cs, struct xt_xlate *xl)
{
struct xtables_rule_match *matchp;
int ret = 1, numeric = cs->options & OPT_NUMERIC;
if (!matchp->match->xlate)
return 0;
- ret = matchp->match->xlate(matchp->match->m, buf, numeric);
+ ret = matchp->match->xlate(matchp->match->m, xl, numeric);
if (!ret)
break;
}
const struct iptables_command_state *cs,
bool append)
{
- struct xt_buf *buf = xt_buf_alloc(10240);
+ struct xt_xlate *xl = xt_xlate_alloc(10240);
int ret;
if (append) {
- xt_buf_add(buf, "add rule %s %s %s ",
+ xt_xlate_add(xl, "add rule %s %s %s ",
family2str[h->family], p->table, p->chain);
} else {
- xt_buf_add(buf, "insert rule %s %s %s ",
+ xt_xlate_add(xl, "insert rule %s %s %s ",
family2str[h->family], p->table, p->chain);
}
- ret = h->ops->xlate(cs, buf);
+ ret = h->ops->xlate(cs, xl);
if (ret)
- printf("%s\n", xt_buf_get(buf));
+ printf("%s\n", xt_xlate_get(xl));
- xt_buf_free(buf);
+ xt_xlate_free(xl);
return ret;
}
kernel_version = LINUX_VERSION(x, y, z);
}
-struct xt_buf {
+struct xt_xlate {
char *data;
int size;
int rem;
int off;
};
-struct xt_buf *xt_buf_alloc(int size)
+struct xt_xlate *xt_xlate_alloc(int size)
{
- struct xt_buf *buf;
+ struct xt_xlate *xl;
- buf = malloc(sizeof(struct xt_buf));
- if (buf == NULL)
+ xl = malloc(sizeof(struct xt_xlate));
+ if (xl == NULL)
xtables_error(RESOURCE_PROBLEM, "OOM");
- buf->data = malloc(size);
- if (buf->data == NULL)
+ xl->data = malloc(size);
+ if (xl->data == NULL)
xtables_error(RESOURCE_PROBLEM, "OOM");
- buf->size = size;
- buf->rem = size;
- buf->off = 0;
+ xl->size = size;
+ xl->rem = size;
+ xl->off = 0;
- return buf;
+ return xl;
}
-void xt_buf_free(struct xt_buf *buf)
+void xt_xlate_free(struct xt_xlate *xl)
{
- free(buf->data);
- free(buf);
+ free(xl->data);
+ free(xl);
}
-void xt_buf_add(struct xt_buf *buf, const char *fmt, ...)
+void xt_xlate_add(struct xt_xlate *xl, const char *fmt, ...)
{
va_list ap;
int len;
va_start(ap, fmt);
- len = vsnprintf(buf->data + buf->off, buf->rem, fmt, ap);
- if (len < 0 || len >= buf->rem)
+ len = vsnprintf(xl->data + xl->off, xl->rem, fmt, ap);
+ if (len < 0 || len >= xl->rem)
xtables_error(RESOURCE_PROBLEM, "OOM");
va_end(ap);
- buf->rem -= len;
- buf->off += len;
+ xl->rem -= len;
+ xl->off += len;
}
-const char *xt_buf_get(struct xt_buf *buf)
+const char *xt_xlate_get(struct xt_xlate *xl)
{
- return buf->data;
+ return xl->data;
}