static int
ebtablesHandleEthHdr(virBufferPtr buf,
virNWFilterHashTablePtr vars,
- ethHdrDataDefPtr ethHdr)
+ ethHdrDataDefPtr ethHdr,
+ bool reverse)
{
char macaddr[VIR_MAC_STRING_BUFLEN];
goto err_exit;
virBufferVSprintf(buf,
- " -s %s %s",
+ " %s %s %s",
+ reverse ? "-d" : "-s",
ENTRY_GET_NEG_SIGN(ðHdr->dataSrcMACAddr),
macaddr);
goto err_exit;
virBufferVSprintf(buf,
- " -d %s %s",
+ " %s %s %s",
+ reverse ? "-s" : "-d",
ENTRY_GET_NEG_SIGN(ðHdr->dataDstMACAddr),
macaddr);
* @ifname : The name of the interface to apply the rule to
* @vars : A map containing the variables to resolve
* @res : The data structure to store the result(s) into
+ * @reverse : Whether to reverse src and dst attributes
*
* Convert a single rule into its representation for later instantiation
*
virNWFilterRuleDefPtr rule,
const char *ifname,
virNWFilterHashTablePtr vars,
- virNWFilterRuleInstPtr res)
+ virNWFilterRuleInstPtr res,
+ bool reverse)
{
char macaddr[VIR_MAC_STRING_BUFLEN],
ipaddr[INET_ADDRSTRLEN],
if (ebtablesHandleEthHdr(&buf,
vars,
- &rule->p.ethHdrFilter.ethHdr))
+ &rule->p.ethHdrFilter.ethHdr,
+ reverse))
goto err_exit;
if (HAS_ENTRY_ITEM(&rule->p.ethHdrFilter.dataProtocolID)) {
if (ebtablesHandleEthHdr(&buf,
vars,
- &rule->p.arpHdrFilter.ethHdr))
+ &rule->p.arpHdrFilter.ethHdr,
+ reverse))
goto err_exit;
virBufferAddLit(&buf, " -p arp");
goto err_exit;
virBufferVSprintf(&buf,
- " --arp-ip-src %s %s",
+ " %s %s %s",
+ reverse ? "--arp-ip-dst" : "--arp-ip-src",
ENTRY_GET_NEG_SIGN(&rule->p.arpHdrFilter.dataARPSrcIPAddr),
ipaddr);
}
goto err_exit;
virBufferVSprintf(&buf,
- " --arp-ip-dst %s %s",
+ " %s %s %s",
+ reverse ? "--arp-ip-src" : "--arp-ip-dst",
ENTRY_GET_NEG_SIGN(&rule->p.arpHdrFilter.dataARPDstIPAddr),
ipaddr);
}
goto err_exit;
virBufferVSprintf(&buf,
- " --arp-mac-src %s %s",
+ " %s %s %s",
+ reverse ? "--arp-mac-dst" : "--arp-mac-src",
ENTRY_GET_NEG_SIGN(&rule->p.arpHdrFilter.dataARPSrcMACAddr),
macaddr);
}
goto err_exit;
virBufferVSprintf(&buf,
- " --arp-mac-dst %s %s",
+ " %s %s %s",
+ reverse ? "--arp-mac-src" : "--arp-mac-dst",
ENTRY_GET_NEG_SIGN(&rule->p.arpHdrFilter.dataARPDstMACAddr),
macaddr);
}
if (ebtablesHandleEthHdr(&buf,
vars,
- &rule->p.ipHdrFilter.ethHdr))
+ &rule->p.ipHdrFilter.ethHdr,
+ reverse))
goto err_exit;
virBufferAddLit(&buf,
goto err_exit;
virBufferVSprintf(&buf,
- " --ip-source %s %s",
+ " %s %s %s",
+ reverse ? "--ip-destination" : "--ip-source",
ENTRY_GET_NEG_SIGN(&rule->p.ipHdrFilter.ipHdr.dataSrcIPAddr),
ipaddr);
goto err_exit;
virBufferVSprintf(&buf,
- " --ip-destination %s %s",
+ " %s %s %s",
+ reverse ? "--ip-source" : "--ip-destination",
ENTRY_GET_NEG_SIGN(&rule->p.ipHdrFilter.ipHdr.dataDstIPAddr),
ipaddr);
goto err_exit;
virBufferVSprintf(&buf,
- " --ip-source-port %s %s",
+ " %s %s %s",
+ reverse ? "--ip-destination-port" : "--ip-source-port",
ENTRY_GET_NEG_SIGN(&rule->p.ipHdrFilter.portData.dataSrcPortStart),
number);
goto err_exit;
virBufferVSprintf(&buf,
- " --ip-destination-port %s %s",
+ " %s %s %s",
+ reverse ? "--ip-source-port" : "--ip-destination-port",
ENTRY_GET_NEG_SIGN(&rule->p.ipHdrFilter.portData.dataDstPortStart),
number);
if (ebtablesHandleEthHdr(&buf,
vars,
- &rule->p.ipv6HdrFilter.ethHdr))
+ &rule->p.ipv6HdrFilter.ethHdr,
+ reverse))
goto err_exit;
virBufferAddLit(&buf,
goto err_exit;
virBufferVSprintf(&buf,
- " --ip6-source %s %s",
+ " %s %s %s",
+ reverse ? "--ip6-destination" : "--ip6-source",
ENTRY_GET_NEG_SIGN(&rule->p.ipv6HdrFilter.ipHdr.dataSrcIPAddr),
ipv6addr);
goto err_exit;
virBufferVSprintf(&buf,
- " --ip6-destination %s %s",
+ " %s %s %s",
+ reverse ? "--ip6-source" : "--ip6-destination",
ENTRY_GET_NEG_SIGN(&rule->p.ipv6HdrFilter.ipHdr.dataDstIPAddr),
ipv6addr);
goto err_exit;
virBufferVSprintf(&buf,
- " --ip6-source-port %s %s",
+ " %s %s %s",
+ reverse ? "--ip6-destination-port" : "--ip6-source-port",
ENTRY_GET_NEG_SIGN(&rule->p.ipv6HdrFilter.portData.dataSrcPortStart),
number);
goto err_exit;
virBufferVSprintf(&buf,
- " --ip6-destination-port %s %s",
+ " %s %s %s",
+ reverse ? "--ip6-source-port" : "--ip6-destination-port",
ENTRY_GET_NEG_SIGN(&rule->p.ipv6HdrFilter.portData.dataDstPortStart),
number);
rule,
ifname,
vars,
- res);
+ res,
+ rule->tt == VIR_NWFILTER_RULE_DIRECTION_INOUT);
if (rc)
return rc;
}
rule,
ifname,
vars,
- res);
+ res,
+ false);
}
break;