FW3_OPT("ipset", setmatch, rule, ipset),
FW3_OPT("helper", cthelper, rule, helper),
- FW3_OPT("set_helper", cthelper, rule, helper),
+ FW3_OPT("set_helper", cthelper, rule, set_helper),
FW3_LIST("proto", protocol, rule, proto),
FW3_OPT("set_mark", mark, rule, set_mark),
FW3_OPT("set_xmark", mark, rule, set_xmark),
+ FW3_OPT("dscp", dscp, rule, dscp),
+ FW3_OPT("set_dscp", dscp, rule, set_dscp),
+
FW3_OPT("target", target, rule, target),
{ }
r->target == FW3_FLAG_MARK)
{
warn_section("rule", r, e, "is set to target MARK but specifies neither "
- "'set_mark' nor 'set_xmark' option");
+ "'set_mark' nor 'set_xmark' option");
return false;
}
- if (r->_dest && r->target == FW3_FLAG_MARK)
+ if (!r->set_dscp.set && r->target == FW3_FLAG_DSCP)
{
- warn_section("rule", r, e, "must not specify 'dest' for MARK target");
+ warn_section("rule", r, e, "is set to target DSCP but specifies no "
+ "'set_dscp' option");
return false;
}
- if (r->set_mark.invert || r->set_xmark.invert)
+ if (r->set_mark.invert || r->set_xmark.invert || r->set_dscp.invert)
{
- warn_section("rule", r, e, "must not have inverted 'set_mark' or 'set_xmark'");
+ warn_section("rule", r, e, "must not have inverted 'set_mark', "
+ "'set_xmark' or 'set_dscp'");
return false;
}
if (!r->_src && !r->_dest && !r->src.any && !r->dest.any)
{
warn_section("rule", r, e, "has neither a source nor a destination zone assigned "
- "- assuming an output r");
+ "- assuming an output rule");
}
if (list_empty(&r->proto))
warn_section("rule", r, e, "has no target specified, defaulting to REJECT");
r->target = FW3_FLAG_REJECT;
}
- else if (r->target > FW3_FLAG_MARK)
+ else if (r->target > FW3_FLAG_DSCP)
{
warn_section("rule", r, e, "has invalid target specified, defaulting to REJECT");
r->target = FW3_FLAG_REJECT;
{
snprintf(chain, sizeof(chain), "zone_%s_helper", rule->src.name);
}
- else if (rule->target == FW3_FLAG_MARK && (rule->_src || rule->src.any))
+ else if (rule->target == FW3_FLAG_MARK || rule->target == FW3_FLAG_DSCP)
{
- snprintf(chain, sizeof(chain), "PREROUTING");
+ if ((rule->_dest && rule->_src) ||
+ (rule->dest.any && rule->src.any))
+ snprintf(chain, sizeof(chain), "FORWARD");
+ else if (rule->src.any && rule->_dest)
+ snprintf(chain, sizeof(chain), "POSTROUTING");
+ else if (rule->dest.any && rule->_src)
+ snprintf(chain, sizeof(chain), "PREROUTING");
+ else if (!rule->dest.set && rule->src.set)
+ snprintf(chain, sizeof(chain), "INPUT");
+ else /* if (!rule->src.set) */
+ snprintf(chain, sizeof(chain), "OUTPUT");
}
else
{
{
const char *name;
struct fw3_mark *mark;
- char buf[sizeof("0xFFFFFFFF/0xFFFFFFFF\0")];
+ char buf[sizeof("0xFFFFFFFF/0xFFFFFFFF")];
switch(rule->target)
{
case FW3_FLAG_MARK:
name = rule->set_mark.set ? "--set-mark" : "--set-xmark";
mark = rule->set_mark.set ? &rule->set_mark : &rule->set_xmark;
- sprintf(buf, "0x%x/0x%x", mark->mark, mark->mask);
+ snprintf(buf, sizeof(buf), "0x%x/0x%x", mark->mark, mark->mask);
fw3_ipt_rule_target(r, "MARK");
fw3_ipt_rule_addarg(r, false, name, buf);
return;
+ case FW3_FLAG_DSCP:
+ snprintf(buf, sizeof(buf), "0x%x", rule->set_dscp.dscp);
+
+ fw3_ipt_rule_target(r, "DSCP");
+ fw3_ipt_rule_addarg(r, false, "--set-dscp", buf);
+ return;
+
case FW3_FLAG_NOTRACK:
fw3_ipt_rule_target(r, "CT");
fw3_ipt_rule_addarg(r, false, "--notrack", NULL);
struct fw3_mac *mac, struct fw3_icmptype *icmptype)
{
struct fw3_ipt_rule *r;
+ struct fw3_device *idev, *odev;
+ struct list_head empty, *idevices, *odevices;
+ INIT_LIST_HEAD(&empty);
+ idevices = odevices = ∅
if (!fw3_is_family(sip, handle->family) ||
!fw3_is_family(dip, handle->family))
}
if (rule->helper.ptr &&
- rule->helper.ptr->proto.protocol != proto->protocol)
+ !fw3_cthelper_check_proto(rule->helper.ptr, proto))
{
info(" ! Skipping protocol %s since helper '%s' does not support it",
fw3_protoname(proto), rule->helper.ptr->name);
}
if (rule->set_helper.ptr &&
- rule->set_helper.ptr->proto.protocol != proto->protocol)
+ !fw3_cthelper_check_proto(rule->set_helper.ptr, proto))
{
info(" ! Skipping protocol %s since helper '%s' does not support it",
fw3_protoname(proto), rule->helper.ptr->name);
return;
}
- r = fw3_ipt_rule_create(handle, proto, NULL, NULL, sip, dip);
- fw3_ipt_rule_sport_dport(r, sport, dport);
- fw3_ipt_rule_device(r, rule->device, rule->direction_out);
- fw3_ipt_rule_icmptype(r, icmptype);
- fw3_ipt_rule_mac(r, mac);
- fw3_ipt_rule_ipset(r, &rule->ipset);
- fw3_ipt_rule_helper(r, &rule->helper);
- fw3_ipt_rule_limit(r, &rule->limit);
- fw3_ipt_rule_time(r, &rule->time);
- fw3_ipt_rule_mark(r, &rule->mark);
- set_target(r, rule);
- fw3_ipt_rule_extra(r, rule->extra);
- set_comment(r, rule->name, num);
- append_chain(r, rule);
+ if (rule->target == FW3_FLAG_DSCP || rule->target == FW3_FLAG_MARK)
+ {
+ if (rule->_src)
+ idevices = &rule->_src->devices;
+ if (rule->_dest)
+ odevices = &rule->_dest->devices;
+ }
+
+ fw3_foreach(idev, idevices)
+ fw3_foreach(odev, odevices)
+ {
+ r = fw3_ipt_rule_create(handle, proto, idev, odev, sip, dip);
+ fw3_ipt_rule_sport_dport(r, sport, dport);
+ fw3_ipt_rule_device(r, rule->device, rule->direction_out);
+ fw3_ipt_rule_icmptype(r, icmptype);
+ fw3_ipt_rule_mac(r, mac);
+ fw3_ipt_rule_ipset(r, &rule->ipset);
+ fw3_ipt_rule_helper(r, &rule->helper);
+ fw3_ipt_rule_limit(r, &rule->limit);
+ fw3_ipt_rule_time(r, &rule->time);
+ fw3_ipt_rule_mark(r, &rule->mark);
+ fw3_ipt_rule_dscp(r, &rule->dscp);
+ set_target(r, rule);
+ fw3_ipt_rule_extra(r, rule->extra);
+ set_comment(r, rule->name, num);
+ append_chain(r, rule);
+ }
}
static void
if ((rule->target == FW3_FLAG_NOTRACK && handle->table != FW3_TABLE_RAW) ||
(rule->target == FW3_FLAG_HELPER && handle->table != FW3_TABLE_RAW) ||
(rule->target == FW3_FLAG_MARK && handle->table != FW3_TABLE_MANGLE) ||
+ (rule->target == FW3_FLAG_DSCP && handle->table != FW3_TABLE_MANGLE) ||
(rule->target < FW3_FLAG_NOTRACK && handle->table != FW3_TABLE_FILTER))
return;